Skip to content

Instantly share code, notes, and snippets.

@tgonzales
Created August 6, 2013 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgonzales/6161108 to your computer and use it in GitHub Desktop.
Save tgonzales/6161108 to your computer and use it in GitHub Desktop.
Exercício - desafio do StummJr
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