Created
May 21, 2014 13:46
-
-
Save isouzasoares/ee38cfad21f2778f9ac9 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
class Editoria(object): | |
def __init__(self, titulo, url, **kwargs): | |
self.titulo = titulo | |
self.url = url | |
self.json_noticia = None | |
def get_json_noticia(self): | |
import urllib | |
import json | |
if not self.json_noticia and self.url: | |
self.json_noticia = json.loads(urllib.urlopen(self.url).read()) | |
if self.json_noticia and self.json_noticia.get('res', None): | |
return self.json_noticia['res'] | |
return [] | |
def prepara_editoria(itens): | |
editorias = [Editoria(**i) for i in itens] | |
return editorias | |
#[[object],[object]] | |
if __name__ == '__main__': | |
itens = [ | |
{'titulo': 'Vrum', 'url': 'http://app.em.com.br/noticia/noticia_127983242361,35/getUltimasNoticiasAcessadas?d1=&d2=&hash=d4efa8dd90dc6171a40782d1bd449a97&limit=3&offset=0'}, | |
] | |
editorias = prepara_editoria(itens) | |
for i in editorias: | |
print i.get_json_noticia() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment