Download app.py from SiteOn/amazonas4: direct link, hf CLI and curl.
- Browser
- Download file 3.48 kB
-
https://huggingface.co/spaces/SiteOn/amazonas4/resolve/main/app.py
- Command line
-
hf download hf://spaces/SiteOn/amazonas4/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SiteOn/amazonas4/resolve/main/app.py
3.48 kB
| import requests | |
| import gradio as gr | |
| from bs4 import BeautifulSoup | |
| # Notícias Revista Oeste | |
| def raspar_noticias_revista_oeste(): | |
| try: | |
| response = requests.get('https://revistaoeste.com/', timeout=10) | |
| except requests.Timeout: | |
| return "O pedido excedeu o tempo limite. Tente novamente mais tarde." | |
| except requests.RequestException as e: | |
| return f"Erro ao fazer a requisição: {e}" | |
| content = response.content | |
| site = BeautifulSoup(content, 'html.parser') | |
| #------------------------------------------------------ | |
| # Notícia principal Revista Oeste | |
| noticias = site.findAll('article', attrs={'class': 'z-0'}) | |
| resultados = ["<div style='font-size: 20px;'><strong>----------------Revista Oeste - Últimas Notícias----------------</strong></div><br>"] | |
| # Notícia principal + noticias laterais quadro preto Revista Oeste | |
| noticias = site.findAll('article', attrs={'class': 'px-4'}) | |
| for noticia in noticias: | |
| titulo = noticia.find('h3', attrs={'class': 'inline'}) | |
| tprincipal = noticia.find('h3', attrs={'class': 'brightness-100 group-hover:brightness-90 text-3xl lg:text-[40px] lg:leading-[56px] transition-filter'}) | |
| link = noticia.find('a', attrs={'class': 'stretched-link'}) | |
| postagem = noticia.find('span', attrs={'class': 'hidden lg:flex items-center text-gray-300 text-xs lg:text-sm relative z-20 mt-4'}) | |
| resultados.append( | |
| f"<div><strong>Título:</strong> {titulo.text if titulo else tprincipal.text}</div>" | |
| f"<div><strong>Link:</strong> <a href='{link['href']}' target='_blank'>{link['href']}</a></div>" | |
| f"<div><strong>Data da Postagem:</strong> {postagem.text if postagem else 'Não disponível'}</div><br>" | |
| ) | |
| # Fim Notícia principal + noticias laterais quadro preto Revista Oeste | |
| #------------------------------------------------------ | |
| #------------------------------------------------------ | |
| # Outras Notícia principal Revista Oeste | |
| noticias = site.findAll('article', attrs={'class': 'card-post--list flex flex-col md:grid relative md:grid-flow-col grid-cols-min-auto grid-rows-min-auto'}) | |
| for noticia in noticias: | |
| titulo = noticia.find('h3') | |
| link = noticia.find('a', attrs={'class': 'card-post__title text-lg leading-6 lg:text-3.5xl font-semibold stretched-link mb-2'}) | |
| postagem = noticia.find('span') | |
| resultados.append( | |
| f"<div><strong></strong> {titulo if titulo else 'Não disponível'}</div>" | |
| f"<div><strong>Link:</strong> <a href='{link['href']}' target='_blank'>{link['href']}</a></div>" | |
| f"<div><strong>Data da Postagem:</strong> {postagem if postagem else 'Não disponível'}</div><br>" | |
| ) | |
| # Fim Outras Notícia principal Revista Oeste | |
| #------------------------------------------------------ | |
| return "\n".join(resultados) | |
| iface_oeste = gr.Interface( | |
| fn=raspar_noticias_revista_oeste, | |
| inputs=[], | |
| outputs="html", | |
| title="Revista Oeste - Notícias", | |
| description="Fique por dentro das últimas notícias da Revista Oeste", | |
| css="footer.svelte-1rjryqp.svelte-1rjryqp.svelte-1rjryqp {display: none !important;} .panel.svelte-vt1mxs {background: #fff !important;} .show-api {display: none !important;} .svelte-mpyp5e a {display: none !important;} .textarea {font-size: 20px !important; }", | |
| allow_flagging="never" | |
| ) | |
| iface_oeste.launch(share=True) |