SiteOn commited on
Commit
e71956f
1 Parent(s): e44d26d

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +52 -0
  2. requeriments.txt +3 -0
  3. start.sh.txt +4 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ from bs4 import BeautifulSoup
4
+
5
+
6
+ # Função para raspar as notícias do Portal do Holanda
7
+ def scrape_news():
8
+
9
+ try:
10
+ # Adicionando um timeout de 10 segundos
11
+ response = requests.get('https://www.portaldoholanda.com.br/', timeout=10)
12
+ except requests.Timeout:
13
+ return "O pedido excedeu o tempo limite. Tente novamente mais tarde."
14
+ except requests.RequestException as e:
15
+ return f"Erro ao fazer a requisição: {e}"
16
+
17
+
18
+ content = response.content
19
+ site = BeautifulSoup(content, 'html.parser')
20
+
21
+ noticias = site.findAll('div', attrs={'class': 'column homenoticia'})
22
+ resultados = ["<div style='font-size: 20px;'><strong>----------------Portal do Holanda - Últimas Notícias----------------</strong></div><br>"]
23
+
24
+ for noticia in noticias:
25
+ titulo = noticia.find('a')
26
+ titulo_text = titulo.text.strip() if titulo else "Sem título"
27
+ subtitulo = noticia.find('a', attrs={'class': 'destaque relacionada'})
28
+ subtitulo_text = subtitulo.text.strip() if subtitulo else "Sem subtítulo"
29
+ link = titulo['href'] if titulo else "#"
30
+ hora = noticia.find('p', attrs={'class': 'destaque ha'})
31
+ hora_text = hora.text.strip() if hora else "Sem horário de postagem"
32
+
33
+ resultados.append(
34
+ f"<div><strong>Título:</strong> {titulo_text if titulo else 'Não disponível'}</div>"
35
+ f"<div><strong>Subtítulo:</strong> {subtitulo_text if subtitulo else 'Não disponível'}</div>"
36
+ f"<div><strong>Link:</strong> <a href='{link}' target='_blank'>{link}</a></div>"
37
+ f"<div><strong>Hora da Postagem:</strong> {hora_text if hora else 'Não disponível'}</div><br>"
38
+ )
39
+
40
+ return "\n".join(resultados)
41
+
42
+ iface_holanda = gr.Interface(
43
+ fn=scrape_news,
44
+ inputs=[],
45
+ outputs="html",
46
+ title="Portal do Holanda - Notícias",
47
+ description="Fique por dentro das últimas notícias do Portal do Holanda",
48
+ css=" .panel.svelte-vt1mxs {background: #fff !important;} .show-api {display: none !important;} .svelte-mpyp5e a {display: none !important;} .textarea {font-size: 20px !important; }",
49
+ allow_flagging= "never"
50
+ )
51
+
52
+ iface_holanda.launch(share=True)
requeriments.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ requests
2
+ gradio
3
+ beautifulsoup4
start.sh.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # setup.sh
2
+ #!/bin/bash
3
+ chmod +x start.sh
4
+ ./start.sh