Skip to content

Username: add more exception handling #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions username/username_profilepic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
14 changes: 11 additions & 3 deletions username/username_twitterdetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down