JayosChaos commited on
Commit
897529c
·
verified ·
1 Parent(s): 03aee39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -29,7 +29,6 @@ def get_nbp_exchange_rate(currency: str) -> float:
29
  else:
30
  raise ValueError(f"Failed to fetch exchange rate for {currency}. HTTP Status: {response.status_code}")
31
 
32
-
33
  @tool
34
  def get_billboard_hot_100_last_countdown() -> list:
35
  """A tool that fetches the latest Billboard Hot 100 countdown with song names and artist names.
@@ -51,22 +50,28 @@ def get_billboard_hot_100_last_countdown() -> list:
51
 
52
  for item in chart_items[:10]:
53
  song_name_elem = item.select_one("h3")
54
- artist_name_elem = item.select_one("span.c-label")
55
 
56
  if song_name_elem and artist_name_elem:
57
  song_name = song_name_elem.get_text(strip=True)
58
- artist_name = artist_name_elem.get_text(strip=True)
59
 
60
- # Handle cases where the artist's name might not be correctly extracted
61
- if not artist_name or artist_name.isdigit():
62
- artist_name = item.select_one("span.c-label.a-font-primary-s").get_text(strip=True)
 
 
 
63
 
64
- top_songs.append({"song": song_name, "artist": artist_name})
 
65
 
66
  return top_songs
67
  else:
68
  raise ValueError(f"Failed to fetch Billboard Hot 100. HTTP Status: {response.status_code}")
69
 
 
 
 
70
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
71
  @tool
72
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
29
  else:
30
  raise ValueError(f"Failed to fetch exchange rate for {currency}. HTTP Status: {response.status_code}")
31
 
 
32
  @tool
33
  def get_billboard_hot_100_last_countdown() -> list:
34
  """A tool that fetches the latest Billboard Hot 100 countdown with song names and artist names.
 
50
 
51
  for item in chart_items[:10]:
52
  song_name_elem = item.select_one("h3")
53
+ artist_name_elem = item.select("span.c-label")
54
 
55
  if song_name_elem and artist_name_elem:
56
  song_name = song_name_elem.get_text(strip=True)
 
57
 
58
+ # The artist name is usually the second span.c-label element in Billboard's structure
59
+ artist_name = None
60
+ for span in artist_name_elem:
61
+ if not span.get_text(strip=True).isdigit(): # Avoid selecting ranking numbers
62
+ artist_name = span.get_text(strip=True)
63
+ break
64
 
65
+ if artist_name:
66
+ top_songs.append({"song": song_name, "artist": artist_name})
67
 
68
  return top_songs
69
  else:
70
  raise ValueError(f"Failed to fetch Billboard Hot 100. HTTP Status: {response.status_code}")
71
 
72
+
73
+
74
+
75
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
76
  @tool
77
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type