File size: 2,374 Bytes
e71956f
 
 
 
 
 
 
8580a4b
e71956f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cab9d59
e71956f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab5d45f
7018034
e71956f
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import requests
import gradio as gr
from bs4 import BeautifulSoup


# Função para raspar as notícias do Portal do Holanda
def scrape_news():
    url = 'https://www.portaldoholanda.com.br'
    
    try:
        # Adicionando um timeout de 10 segundos
        response = requests.get('https://www.portaldoholanda.com.br/', 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')

    noticias = site.findAll('div', attrs={'class': 'column homenoticia'})
    resultados = ["<div style='font-size: 20px;'><strong>----------------Portal do Holanda - Últimas Notícias----------------</strong></div><br>"]

    for noticia in noticias:
        titulo = noticia.find('a')
        titulo_text = titulo.text.strip() if titulo else "Sem título"
        subtitulo = noticia.find('a', attrs={'class': 'destaque relacionada'})
        subtitulo_text = subtitulo.text.strip() if subtitulo else "Sem subtítulo"
        link = url + titulo['href'] if titulo else "#"
        hora = noticia.find('p', attrs={'class': 'destaque ha'})
        hora_text = hora.text.strip() if hora else "Sem horário de postagem"

        resultados.append(
            f"<div><strong>Título:</strong> {titulo_text if titulo else 'Não disponível'}</div>"
            f"<div><strong>Subtítulo:</strong> {subtitulo_text if subtitulo else 'Não disponível'}</div>"
            f"<div><strong>Link:</strong> <a href='{link}' target='_blank'>{link}</a></div>"
            f"<div><strong>Hora da Postagem:</strong> {hora_text if hora else 'Não disponível'}</div><br>"
        )

    return "\n".join(resultados)

iface_holanda = gr.Interface(
    fn=scrape_news, 
    inputs=[], 
    outputs="html",
    title="Portal do Holanda - Notícias",
    description="Fique por dentro das últimas notícias do Portal do Holanda!",
    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_holanda.launch(share=True)