Skip to content

Instantly share code, notes, and snippets.

@wsricardo
Last active May 29, 2023 18:04
Show Gist options
  • Save wsricardo/3dad7b67651175e664713631edcf3344 to your computer and use it in GitHub Desktop.
Save wsricardo/3dad7b67651175e664713631edcf3344 to your computer and use it in GitHub Desktop.
Função que obtem as notícias via feed RSS dos vários editoriais do site de notícias "Folha de São Paulo. parte do projeto NewsCrawler e Sofia News em https://github.com/wsricardo/news-crawler

Testes Algoritmo 1 e Algoritmo 2.

Teste trackFolhaSP

import sys

# Algoritmo 1 ( trackFolhaSP ).
f1  = trackFolhaSP()

sys.getsizeof(f1)

#104

# --------

#Algoritmo 2 ( trackFolhaSPv2 ).
f2 = trackFolhaSP()

sys.getsizeof( fsp_news_list )

#248
for i in f2:
  print(i)

Output:


 {'Editorial': 'Em Cima Da Hora', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875daa960>}
{'Editorial': 'Opinião', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875daa030>}
{'Editorial': 'Política', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875daaa40>}
{'Editorial': 'Mundo', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875dab990>}
{'Editorial': 'Mercado', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875da93f0>}
{'Editorial': 'Cotidiano', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875da9ee0>}
{'Editorial': 'Educação', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875de5150>}
{'Editorial': 'Equilíbrio', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875de7760>}
{'Editorial': 'Esporte', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875da93f0>}
{'Editorial': 'Ilustrada', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875da9930>}
{'Editorial': 'Ilustríssima', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875de6030>}
{'Editorial': 'Ciência', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875dc5fc0>}
{'Editorial': 'Ambiente', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875de7ca0>}
{'Editorial': 'Tec', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875dc4580>}
{'Editorial': 'Comida', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875de60a0>}
{'Editorial': 'Saúde', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875dc6730>}
{'Editorial': 'Folhinha', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875dc7df0>}
{'Editorial': 'Turismo', 'Noticias': <generator object trackFolhaSP.<locals>.<genexpr>.<genexpr> at 0x7f6875de5a80>}
for j in fsp_news_list:
    print(j)

Output:

{'Editorial': 'Em Cima Da Hora', 'Noticias': [{'Title': 'Lula chama encontro com Maduro de momento histórico que revive política externa', 'Summary': 'O presidente Luiz Inácio <a href="https://www1.folha.uol.com.br/folha-topicos/lula/" rel="" target="">Lula</a> da Silva (PT) afirmou nesta segunda (29) que a visita do ditador da Venezuela, Nicolás Maduro, é um momento histórico e que "reflete uma política externa séria".\n<a href="https://redir.folha.com.br/redir/online/emcimadahora/rss091/*https://www1.folha.uol.com.br/mundo/2023/05/lula-chama-encontro-com-maduro-de-momento-historico-que-revive-politica-externa.shtml">Leia mais</a> (05/29/2023 - 13h30)', 'href': 'https://www1.folha.uol.com.br/mundo/2023/05/lula-chama-encontro-com-maduro-de-momento-historico-que-revive-politica-externa.shtml'}, {'Title': 'Priyanka Chopra, primeira atriz indiana a engatar carreira no Ocidente', 'Summary': 'Bollywood, o nome informal da indústria cinematográfica da Índia, é quase um mundo à parte. Só uma fração de sua produção colossal, de cerca de 2.000 filmes por ano, chega às telas do Ocidente. Astros como Sharukh Khan são famosos em todo o sul da Ásia, mas praticamente desconhecidos no resto do mundo.\n<a href="https://redir.folha.com.br/redir/online/emcimadahora/rss091/*https://f5.folha.uol.com.br/colunistas/tonygoes/2023/05/priyanka-chopra-primeira-atriz-indiana-a-engatar-carreira-no-ocidente.shtml">Leia mais</a> (05/29/2023 - 13h27)', 'href': 'https://f5.folha.uol.com.br/colunistas/tonygoes/2023/05/priyanka-chopra-primeira-atriz-indiana-a-engatar-carreira-no-ocidente.shtml'}, {'Title': 'Polícia prende 33 suspeitos de aplicar golpe do nude em RS e SC', 'Summary': 'Uma operação na manhã desta segunda-feira (29) em 11 cidades do <a href="https://www1.folha.uol.com.br/folha-topicos/rio-grande-do-sul-estado/" rel="" target="">Rio Grande do Sul </a>e <a href="https://www1.folha.uol.com.br/folha-topicos/santa-catarina-estado/" rel="" target="">Santa Catarina</a> prendeu uma quadrilha que aplicava o golpe dos nudes. Conforme a Polícia Civil gaúcha, foram detidos 33 suspeitos e identificadas 80 vítimas em 12 estados do Brasil.\n<a href="https://redir.folha.com.br/redir/online/emcimadahora/rss091/*https://www1.folha.uol.com.br/cotidiano/2023/05/policia-prende-33-suspeitos-de-aplicar-golpe-do-nude-em-rs-e-sc.shtml">Leia mais</a> (05/29/2023 - 13h19)', 'href': 'https://www1.folha.uol.com.br/cotidiano/2023/05/policia-prende-33-suspeitos-de-aplicar-golpe-do-nude-em-rs-e-sc.shtml'}, {'Title': 'Empresa oferece R$ 9,2 milhões por mês para operar Smart Sampa', 'Summary': 'O pregão do <a href="https://www1.folha.uol.com.br/cotidiano/2023/04/tribunal-libera-edital-que-preve-implantacao-de-reconhecimento-facial-em-sao-paulo.shtml" rel="" target="">Smart Sampa</a>, programa da Prefeitura de <a href="https://www1.folha.uol.com.br/folha-topicos/sao-paulo/" rel="" target="">São Paulo</a> que pretende instalar 20 mil câmeras de segurança com tecnologia de reconhecimento facial na cidade, selecionou um lance de R$ 9,2 milhões por mês para operar o sistema. Se a oferta for confirmada, o vencedor da licitação deve faturar um total de R$ 552 milhões ao longo de 60 meses.\n<a href="https://redir.folha.com.br/redir/online/emcimadahora/rss091/*https://www1.folha.uol.com.br/cotidiano/2023/05/empresa-oferece-r-92-milhoes-por-mes-para-operar-smart-sampa.shtml">Leia mais</a> (05/29/2023 - 13h15)', 'href': 'https://www1.folha.uol.com.br/cotidiano/2023/05/empresa-oferece-r-92-milhoes-por-mes-para-operar-smart-sampa.shtml'}, {'Title': 'Fernanda Montenegro dará árvore para Zé Celso, que plantará presente em terreno de Silvio Santos', 'Summary': 'A atriz<a href="https://www1.folha.uol.com.br/folha-topicos/fernanda-montenegro/" rel="" target=""> Fernanda Montenegro</a> e sua filha<a href="https://www1.folha.uol.com.br/colunas/fernandatorres/" rel="" target="">, Fernanda Torres,</a> não poderão comparecer ao<a href="https://www1.folha.uol.com.br/colunas/monicabergamo/2023/04/ze-celso-convidara-silvio-santos-para-casamento-e-pedira-terreno-do-teatro-oficina-de-presente.shtml" rel="" target=""> casamento </a>de <a href="https://www1.folha.uol.com.br/colunas/monicabergamo/2021/10/filme-sobre-reencontro-de-reynaldo-gianecchini-com-ze-celso-estreia-na-mostra-de-sp.shtml">José Celso Martinez </a><a href="https://www1.folha.uol.com.br/colunas/monicabergamo/2021/10/filme-sobre-reencontro-de-reynaldo-gianecchini-com-ze-celso-estreia-na-mostra-de-sp.shtml">Corrêa</a>, 86, e Marcelo Drummond, 60, no próximo dia 6, em São Paulo, mas preparam um presente especial: vão dar um ipê ao casal. E não trata-se de uma muda não, mas, sim, de uma árvore já grande.\n<a href="https://redir.folha.com.br/redir/online/emcimadahora/rss091/*https://www1.folha.uol.com.br/colunas/monicabergamo/2023/05/fernanda-montenegro-dara-arvore-para-ze-celso-que-plantara-presente-em-terreno-de-silvio-santos.shtml">Leia mais</a> (05/29/2023 - 13h07)', 'href': 'https://www1.folha.uol.com.br/colunas/monicabergamo/2023/05/fernanda-montenegro-dara-arvore-para-ze-celso-que-plantara-presente-em-terreno-de-silvio-santos.shtml'}, ... ]

# Função que obtem as notícias via feed RSS dos vários editoriais do site de notícias
# "Folha de São Paulo.
# Chttps://github.com/wsricardo/news-crawler
# Using 'list' type for data structure
def trackFolhaSP():
"""
Track página da "Folha de São Paulo"
"""
fsp_editoriais = [
('Em Cima Da Hora', 'https://feeds.folha.uol.com.br/emcimadahora/rss091.xml'),
('Opinião', 'https://feeds.folha.uol.com.br/opiniao/rss091.xml' ) ,
( 'Política', 'https://feeds.folha.uol.com.br/poder/rss091.xml') ,
('Mundo', 'https://feeds.folha.uol.com.br/mundo/rss091.xml'),
('Mercado','https://feeds.folha.uol.com.br/mercado/rss091.xml'),
('Cotidiano','https://feeds.folha.uol.com.br/cotidiano/rss091.xml'),
('Educação', 'https://feeds.folha.uol.com.br/educacao/rss091.xml'),
('Equilíbrio', 'https://feeds.folha.uol.com.br/equilibrio/rss091.xml'),
('Esporte','https://feeds.folha.uol.com.br/esporte/rss091.xml'),
('Ilustrada', 'https://feeds.folha.uol.com.br/ilustrada/rss091.xml'),
('Ilustríssima','https://feeds.folha.uol.com.br/ilustrissima/rss091.xml'),
('Ciência','https://feeds.folha.uol.com.br/ciencia/rss091.xml'),
('Ambiente','https://feeds.folha.uol.com.br/ambiente/rss091.xml'),
('Tec','https://feeds.folha.uol.com.br/tec/rss091.xml'),
('Comida','https://feeds.folha.uol.com.br/comida/rss091.xml'),
('Saúde','https://feeds.folha.uol.com.br/equilibrioesaude/rss091.xml'),
('Folhinha','https://feeds.folha.uol.com.br/folhinha/rss091.xml'),
('Turismo','https://feeds.folha.uol.com.br/turismo/rss091.xml'),
]
fsp_feeds = [
{ 'Editorial': j[0], 'FeedData': fp.parse( j[1] ) }
for j in fsp_editoriais
]
# Lista de editoriais com suas respectivas listas de notícias. Para cada editorial extraido um lista de notícias.
fsp_news_list = [
{
'Editorial': i[ 'Editorial' ],
'Noticias': [ {
'Title': j.title,
'Summary': j.summary,
'href': j['link'].split('*')[1]
} for j in i[ 'FeedData' ].entries ]
} for i in fsp_feeds
]
return fsp_news_list
# Using 'tuple' type for data structure
def trackFolhaSP():
"""
Track página da "Folha de São Paulo"
"""
fsp_editoriais = (
('Em Cima Da Hora', 'https://feeds.folha.uol.com.br/emcimadahora/rss091.xml'),
('Opinião', 'https://feeds.folha.uol.com.br/opiniao/rss091.xml' ) ,
( 'Política', 'https://feeds.folha.uol.com.br/poder/rss091.xml') ,
('Mundo', 'https://feeds.folha.uol.com.br/mundo/rss091.xml'),
('Mercado','https://feeds.folha.uol.com.br/mercado/rss091.xml'),
('Cotidiano','https://feeds.folha.uol.com.br/cotidiano/rss091.xml'),
('Educação', 'https://feeds.folha.uol.com.br/educacao/rss091.xml'),
('Equilíbrio', 'https://feeds.folha.uol.com.br/equilibrio/rss091.xml'),
('Esporte','https://feeds.folha.uol.com.br/esporte/rss091.xml'),
('Ilustrada', 'https://feeds.folha.uol.com.br/ilustrada/rss091.xml'),
('Ilustríssima','https://feeds.folha.uol.com.br/ilustrissima/rss091.xml'),
('Ciência','https://feeds.folha.uol.com.br/ciencia/rss091.xml'),
('Ambiente','https://feeds.folha.uol.com.br/ambiente/rss091.xml'),
('Tec','https://feeds.folha.uol.com.br/tec/rss091.xml'),
('Comida','https://feeds.folha.uol.com.br/comida/rss091.xml'),
('Saúde','https://feeds.folha.uol.com.br/equilibrioesaude/rss091.xml'),
('Folhinha','https://feeds.folha.uol.com.br/folhinha/rss091.xml'),
('Turismo','https://feeds.folha.uol.com.br/turismo/rss091.xml'),
)
fsp_feeds = (
{ 'Editorial': j[0], 'FeedData': fp.parse( j[1] ) }
for j in fsp_editoriais
)
# Lista de editoriais com suas respectivas listas de notícias. Para cada editorial extraido um lista de notícias.
fsp_news_list = (
{
'Editorial': i[ 'Editorial' ],
'Noticias': ( {
'Title': j.title,
'Summary': j.summary,
'href': j['link'].split('*')[1]
} for j in i[ 'FeedData' ].entries )
} for i in fsp_feeds
)
return fsp_news_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment