Skip to content

Commit

Permalink
now working with new quora ui
Browse files Browse the repository at this point in the history
  • Loading branch information
csu committed Aug 6, 2014
1 parent 0de8620 commit ba24105
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
v0.1.2, 26 July 2014 -- Fixed to work with new Quora UI.
v0.1.1, 26 July 2014 -- Readme.
v0.1, 26 July 2014 -- Initial release.
v0.1.0, 26 July 2014 -- Initial release.
7 changes: 4 additions & 3 deletions debug.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from quora import Quora, Activity

quora = Quora()
activity = quora.get_activity('Christopher-J-Su')
quora.get_user_stats('Christopher-J-Su')
# activity = quora.get_activity('Christopher-J-Su')
# print activity.answers
# print activity.question_follows
print activity.user_follows
# print activity.user_follows
# print activity.upvotes
# print activity.questions

print quora.get_activity_keys()
# print quora.get_activity_keys()
69 changes: 44 additions & 25 deletions quora/pyquora.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def check_activity_type(description):
else: # hopefully.
return ACTIVITY_ITEM_TYPES.USER_FOLLOW

def is_new_ui(soup):
return soup.find('div', attrs={'class': 'ProfileTabs'}) is not None

####################################################################
# API
####################################################################
Expand All @@ -61,32 +64,48 @@ class Quora:
@staticmethod
def get_user_stats(user):
soup = BeautifulSoup(requests.get('http://www.quora.com/' + user).text)
user_dict = { 'username': user }
user_dict['name'] = soup.find('h1').find('span', class_='user').string

if soup.find('div', class_="empty_area br10 light") is not None:
attributes = ['Followers', 'Following', 'Topics', 'Blogs', 'Posts', 'Questions', 'Answers', 'Reviews', 'Edits']

for item in soup.findAll('li', class_="tab #"):
label = item.find('strong').string
if label in attributes:
user_dict[label.lower()] = try_cast(item.find('span').string)
else:
attributes_to_href_suffix = {
'followers': 'followers',
'following': 'following',
'topics': 'topics',
'blogs': 'blogs',
'posts': 'all_posts',
'questions': 'questions',
'answers': 'answers',
'edits': 'log'
user_dict = {'username': user}

if is_new_ui(soup):
classes_to_attributes = {
'ProfileTabsFollowers': 'followers',
'ProfileTabsFollowing': 'following',
'ProfileTabsQuestions': 'questions',
'ProfileTabsAnswers': 'answers',
'ProfileTabsPosts': 'posts',
'ProfileTabsReviews': 'reviews',
'ProfileTabsOperations': 'edits'
}
for attribute, suffix in attributes_to_href_suffix.iteritems():
try:
user_dict[attribute] = get_count_for_user_href(soup, user, suffix)
except:
pass
for item in soup.find('div', attrs={'class': 'ProfileTabs'}).findAll('li'):
for key in classes_to_attributes.keys():
if key in item.get("class"):
user_dict[classes_to_attributes[key]] = try_cast(item.find('span').string)
else:
user_dict['name'] = soup.find('h1').find('span', class_='user').string

if soup.find('div', class_="empty_area br10 light") is not None:
attributes = ['Followers', 'Following', 'Topics', 'Blogs', 'Posts', 'Questions', 'Answers', 'Reviews', 'Edits']

for item in soup.findAll('li', class_="tab #"):
label = item.find('strong').string
if label in attributes:
user_dict[label.lower()] = try_cast(item.find('span').string)
else:
attributes_to_href_suffix = {
'followers': 'followers',
'following': 'following',
'topics': 'topics',
'blogs': 'blogs',
'posts': 'all_posts',
'questions': 'questions',
'answers': 'answers',
'edits': 'log'
}
for attribute, suffix in attributes_to_href_suffix.iteritems():
try:
user_dict[attribute] = get_count_for_user_href(soup, user, suffix)
except:
pass
return user_dict

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='quora',
version='0.1.1',
version='0.1.2',
description='Fetches and parses data from Quora.',
author='Christopher Su',
author_email='[email protected]',
Expand Down

0 comments on commit ba24105

Please sign in to comment.