Created
August 6, 2013 00:58
-
-
Save tgonzales/6161108 to your computer and use it in GitHub Desktop.
Exercício - desafio do StummJr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from operator import itemgetter | |
def get_controversial_score(limit): | |
results=[] | |
page = requests.get('http://api.reddit.com/controversial?limit=%s'% (limit)) | |
if page.status_code != 200: | |
return None | |
dados = json.loads(page.content) | |
for link in dados['data']['children']: | |
score = link['data']['ups'] - (link['data']['downs'] * 2 ) | |
results.append((link['data']['url'],score)) | |
return sorted(results, key=itemgetter(1), reverse=True) | |
if __name__=='__main__': | |
print 'WebScraping no Reddit by StummJr' | |
pega_dados = get_controversial_score(20) | |
print pega_dados |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment