Diogogp24 commited on
Commit
ee43a34
·
verified ·
1 Parent(s): 0bcf593

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -39
app.py CHANGED
@@ -10,49 +10,34 @@ from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
- class ZeroZeroTeamTool(Tool):
14
- name = "get_team_info"
15
- description = "Acede ao ZeroZero para obter resultados recentes ou próximos jogos de uma equipa de futebol."
16
- inputs = {
17
- "team_name": {
18
- "type": "string",
19
- "description": "O nome da equipa (ex: 'Benfica', 'FC Porto', 'Sporting').",
20
- },
21
- "info_type": {
22
- "type": "string",
23
- "description": "O tipo de info: 'resultados' para jogos passados ou 'proximos' para jogos futuros.",
24
- }
25
- }
26
- output_type = "string"
27
-
28
- def forward(self, team_name: str, info_type: str):
29
- # NOTA: Em produção, o zerozero pode bloquear requests simples.
30
- # Esta lógica simula a procura e extração.
31
- search_url = f"https://www.zerozero.pt/search.php?input_search={team_name.replace(' ', '+')}"
32
 
 
33
  headers = {
34
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
35
  }
36
-
37
- try:
38
- # 1. Procurar a equipa e obter o ID/URL (simplificado)
39
- response = requests.get(search_url, headers=headers, timeout=10)
40
- if response.status_code != 200:
41
- return "Não consegui aceder ao ZeroZero de momento (Erro de ligação)."
42
-
43
- soup = BeautifulSoup(response.text, 'html.parser')
44
-
45
- # Aqui precisarias de lógica específica para navegar nas tabelas do ZZ
46
- # O ZZ usa classes como 'zz-entidade-jogos' ou id='informacao_equipa'
47
-
48
- return f"Simulação: Encontrei os {info_type} para {team_name}. [Aqui apareceria a lista extraída do HTML]"
49
 
50
- except Exception as e:
51
- return f"Erro ao procurar informações: {str(e)}"
52
-
53
- # Para usar no teu CodeAgent:
54
- # team_tool = ZeroZeroTeamTool()
55
- # agent = CodeAgent(tools=[team_tool, DuckDuckGoSearchTool()], model=model)
56
 
57
  @tool
58
  def get_current_time_in_timezone(timezone: str) -> str:
 
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
+ def get_football_team_info(team_name: str, info_type: str) -> str:
14
+ """A tool that fetches football team information (results or upcoming matches) from ZeroZero.
15
+ Args:
16
+ team_name: The name of the football team (e.g., 'Benfica', 'Sporting').
17
+ info_type: Type of information to fetch: 'resultados' (past matches) or 'proximos' (future matches).
18
+ """
19
+ try:
20
+ # Formata o nome para a busca do ZeroZero
21
+ search_query = team_name.replace(" ", "+")
22
+ base_url = "https://www.zerozero.pt"
23
+ search_url = f"{base_url}/search.php?input_search={search_query}"
 
 
 
 
 
 
 
 
24
 
25
+ # Headers para evitar bloqueio imediato (fingir ser um browser)
26
  headers = {
27
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
28
  }
29
+
30
+ response = requests.get(search_url, headers=headers, timeout=10)
31
+
32
+ if response.status_code == 200:
33
+ # Aqui o Agente recebe o link de pesquisa se não conseguirmos fazer o parse direto
34
+ # Mas vamos devolver uma resposta estruturada:
35
+ return f"Podes consultar os {info_type} do {team_name} diretamente no ZeroZero aqui: {search_url}"
36
+ else:
37
+ return f"O ZeroZero devolveu um erro {response.status_code}. Tenta pesquisar manualmente por {team_name}."
 
 
 
 
38
 
39
+ except Exception as e:
40
+ return f"Erro ao tentar aceder a informações do {team_name}: {str(e)}"
 
 
 
 
41
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str: