Spaces:
Runtime error
Runtime error
Upload bloco_de_carnaval_info_finder.py
#2
by lokami - opened
- bloco_de_carnaval_info_finder.py +132 -0
bloco_de_carnaval_info_finder.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, VisitWebpageTool
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import pandas as pd
|
| 4 |
+
def bloco_de_carnaval_info_finder_agent_maker(model):
|
| 5 |
+
search_web = DuckDuckGoSearchTool()
|
| 6 |
+
visit_web = VisitWebpageTool()
|
| 7 |
+
|
| 8 |
+
return CodeAgent(
|
| 9 |
+
tools=[search_web, visit_web],
|
| 10 |
+
additional_authorized_imports=['pandas', 'bs4', 'json'],
|
| 11 |
+
model=model,
|
| 12 |
+
add_base_tools=True
|
| 13 |
+
description="""This agent receives a São Paulo neighborhood and a date (yyyy-mm-dd)
|
| 14 |
+
and return a JSON with the blocos de carnaval that will happen
|
| 15 |
+
in that neighborhood on that date and informations about the
|
| 16 |
+
blocos de carnaval. The agent uses the website
|
| 17 |
+
https://www.blocosderua.com/programacao-blocos-de-carnaval-sp
|
| 18 |
+
for that.
|
| 19 |
+
|
| 20 |
+
The webpage works as a REST API, so, to seach the day 2025-03-02
|
| 21 |
+
in the "Capão Redondo" neighborhood, I enter in the
|
| 22 |
+
"https://www.blocosderua.com/programacao-blocos-de-carnaval-sp?data=20250302&bairro=Capão+Redondo".
|
| 23 |
+
This webpage contains various informations, such as a list of blocos de carnaval
|
| 24 |
+
and the links to their info. I need that the code enters in the information webpage
|
| 25 |
+
to get the information about the bloco de carnaval.
|
| 26 |
+
|
| 27 |
+
The webpage works as a REST API, so, to seach the day 2025-03-02
|
| 28 |
+
in the "Capão Redondo" neighborhood, it enters in the
|
| 29 |
+
"https://www.blocosderua.com/programacao-blocos-de-carnaval-sp?data=20250302&bairro=Capão+Redondo".
|
| 30 |
+
This webpage contains various informations, such as a list of blocos de carnaval
|
| 31 |
+
and the links to their info. The agent enter in each link to get the informations about the bloco de carnaval
|
| 32 |
+
and return a JSON with the informations about the blocos de carnaval in the following format:
|
| 33 |
+
|
| 34 |
+
{
|
| 35 |
+
"blocos": [
|
| 36 |
+
{
|
| 37 |
+
"name": "Bloco 1",
|
| 38 |
+
"time": "10:00",
|
| 39 |
+
"location": "Rua 1",
|
| 40 |
+
"description": "Description 1",
|
| 41 |
+
"link": "Link 1",
|
| 42 |
+
"price" "free"
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"name": "Bloco 2",
|
| 46 |
+
"time": "11:00",
|
| 47 |
+
"location": "Rua 2",
|
| 48 |
+
"description": "Description 2",
|
| 49 |
+
"link": "Link 2",
|
| 50 |
+
"price" "paid"
|
| 51 |
+
}
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
The list of dates is as follows:
|
| 56 |
+
02/Mar
|
| 57 |
+
03/Mar
|
| 58 |
+
04/Mar
|
| 59 |
+
06/Mar
|
| 60 |
+
07/Mar
|
| 61 |
+
08/Mar
|
| 62 |
+
09/Mar
|
| 63 |
+
16/Mar
|
| 64 |
+
26/Apr
|
| 65 |
+
|
| 66 |
+
The list of available neighborhoods is:
|
| 67 |
+
Aricanduva
|
| 68 |
+
Barra Funda
|
| 69 |
+
Bela Vista
|
| 70 |
+
Brasilândia
|
| 71 |
+
Brooklin
|
| 72 |
+
Butantã
|
| 73 |
+
Campo Limpo
|
| 74 |
+
Capão Redondo
|
| 75 |
+
Casa Verde
|
| 76 |
+
Centro
|
| 77 |
+
Cidade Ademar
|
| 78 |
+
Consolação
|
| 79 |
+
Ermelino Matarazzo
|
| 80 |
+
Freguesia do Ó
|
| 81 |
+
Guaianases
|
| 82 |
+
Guaianazes
|
| 83 |
+
Guarapiranga
|
| 84 |
+
Ibirapuera
|
| 85 |
+
Interlagos
|
| 86 |
+
Ipiranga
|
| 87 |
+
Itaim Paulista
|
| 88 |
+
Itaquera
|
| 89 |
+
Jabaquara
|
| 90 |
+
Jardim Maringa
|
| 91 |
+
Jardim Monte Azul
|
| 92 |
+
Jardim Ângela
|
| 93 |
+
Lapa
|
| 94 |
+
Lauzane Paulista
|
| 95 |
+
Limão
|
| 96 |
+
M Boi Mirim
|
| 97 |
+
M'Boi Mirim
|
| 98 |
+
Moema
|
| 99 |
+
Mooca
|
| 100 |
+
Morumbi
|
| 101 |
+
Parelheiros
|
| 102 |
+
Parque Ipe
|
| 103 |
+
Penha
|
| 104 |
+
Perdizes
|
| 105 |
+
Perus
|
| 106 |
+
Pinheiros
|
| 107 |
+
Pirituba
|
| 108 |
+
Pompeia
|
| 109 |
+
Santa Cecilia
|
| 110 |
+
Santa Cecília
|
| 111 |
+
Santana
|
| 112 |
+
Santo Amaro
|
| 113 |
+
Sapopemba
|
| 114 |
+
São Mateus
|
| 115 |
+
São Miguel Paulista
|
| 116 |
+
Tatuapé
|
| 117 |
+
Tremembé
|
| 118 |
+
Tucuruvi
|
| 119 |
+
Vila Carrão
|
| 120 |
+
Vila Cisper
|
| 121 |
+
Vila Guilherme
|
| 122 |
+
Vila Guilhermina
|
| 123 |
+
Vila Leopoldina
|
| 124 |
+
Vila Madalena
|
| 125 |
+
Vila Mariana
|
| 126 |
+
Vila Olimpia
|
| 127 |
+
Vila Olímpia
|
| 128 |
+
Vila Prudente
|
| 129 |
+
Vila Regente Feijó
|
| 130 |
+
Vila São José
|
| 131 |
+
Vila Virginia"""
|
| 132 |
+
)
|