From 04fec836ee8c58cc7e7f6d11a7ab3ff2a3cc0dd8 Mon Sep 17 00:00:00 2001 From: KhasMek Date: Wed, 16 Aug 2017 05:46:41 -0600 Subject: [PATCH 1/2] username: add exception handling for twitterdetails This will now print the error and continue on with discovery if there is a problem with the api keys, searched account publicity or any other error. --- username/username_twitterdetails.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/username/username_twitterdetails.py b/username/username_twitterdetails.py index fc75b13e..887136cd 100755 --- a/username/username_twitterdetails.py +++ b/username/username_twitterdetails.py @@ -32,9 +32,17 @@ def twitterdetails(username): f = open("temptweets.txt", "w+") # writing tweets to temp file- last 1000 - for tweet in tweepy.Cursor(api.user_timeline, id=username).items(1000): - f.write(tweet.text.encode("utf-8")) - f.write("\n") + try: + for tweet in tweepy.Cursor(api.user_timeline, id=username).items(1000): + f.write(tweet.text.encode("utf-8")) + f.write("\n") + except tweepy.error.TweepError as e: + if '401' in e.message: + print colored(style.BOLD + + '[!] Error: API Keys are invalid or Twitter account set to private.\n' + + style.END, 'red') + else: + print colored(style.BOLD + '[!] Error: ' + str(e) + '.\n' + style.END, 'red') # extracting hashtags f = open('temptweets.txt', 'r') From ebb632f4698a1359c21039ee80ec1bb4229eb3d2 Mon Sep 17 00:00:00 2001 From: KhasMek Date: Wed, 16 Aug 2017 06:07:09 -0600 Subject: [PATCH 2/2] username: add exception handling for profilepics --- username/username_profilepic.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/username/username_profilepic.py b/username/username_profilepic.py index 09b1c8f0..12efdf96 100755 --- a/username/username_profilepic.py +++ b/username/username_profilepic.py @@ -23,15 +23,18 @@ def extracting(imglinks, username, prourl, tag, attribute, value, finattrib, pro res = requests.get(prourl) soup = BeautifulSoup(res.content, "lxml") img = soup.find(tag, {attribute: value}) - if profile == "ask.fm": - img[finattrib] = "http:" + img[finattrib] - imglinks.append(img[finattrib]) - path = "profile_pic/" + username + "/" + profile + ".jpg" - urllib.urlretrieve(img[finattrib], path) - else: - imglinks.append(img[finattrib]) - path = "profile_pic/" + username + "/" + profile + ".jpg" - urllib.urlretrieve(img[finattrib], path) + try: + if profile == "ask.fm": + img[finattrib] = img[finattrib] + imglinks.append(img[finattrib]) + path = "profile_pic/" + username + "/" + profile + ".jpg" + urllib.urlretrieve(img[finattrib], path) + else: + imglinks.append(img[finattrib]) + path = "profile_pic/" + username + "/" + profile + ".jpg" + urllib.urlretrieve(img[finattrib], path) + except TypeError as e: + colored(style.BOLD + '[!] Error: ' + str(e) + '.\n' + style.END, 'red') return imglinks