Skip to content

Instantly share code, notes, and snippets.

@nonamenix
Last active August 29, 2015 14:16
Show Gist options
  • Save nonamenix/d376f133d5213392bc36 to your computer and use it in GitHub Desktop.
Save nonamenix/d376f133d5213392bc36 to your computer and use it in GitHub Desktop.
from lxml import html
class User(object):
def __init__(self, username):
self.username = username
def achievements(self):
try:
page = html.parse(user_achievements_url %{'username':self.username})
except IOError:
return []
else:
cards = page.xpath(achievement_card_xpath)
return [card.text for card in cards]
@staticmethod
def show_raiting(usernames):
user_achievements_url = 'http://www.codecademy.com/users/%(username)s/achievements'
achievement_card_xpath = "//*[contains(@class, 'achievement-card')]/h5"
users = [User(name) for name in usernames]
raiting = dict([(user.username, len(user.achievements())) for user in users])
print '# username cards'
for i, user in enumerate(sorted(raiting)):
print i+1, user, raiting[user]
usernames = ['_nonamenix', ]
User.show_raiting(usernames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment