Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,31 +49,19 @@ def get_billboard_hot_100_last_countdown() -> list:
|
|
| 49 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 50 |
|
| 51 |
top_songs = []
|
| 52 |
-
chart_items = soup.select("li.o-chart-results-list__item")
|
|
|
|
| 53 |
|
| 54 |
-
for
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if song_name_elem and artist_name_elem:
|
| 59 |
-
song_name = song_name_elem.get_text(strip=True)
|
| 60 |
-
|
| 61 |
-
# The artist name is usually the second span.c-label element in Billboard's structure
|
| 62 |
-
artist_name = None
|
| 63 |
-
for span in artist_name_elem:
|
| 64 |
-
if not span.get_text(strip=True).isdigit(): # Avoid selecting ranking numbers
|
| 65 |
-
artist_name = span.get_text(strip=True)
|
| 66 |
-
break
|
| 67 |
-
|
| 68 |
-
if artist_name:
|
| 69 |
-
top_songs.append({"song": song_name, "artist": artist_name})
|
| 70 |
|
| 71 |
return top_songs
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
-
|
| 77 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 78 |
@tool
|
| 79 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 49 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 50 |
|
| 51 |
top_songs = []
|
| 52 |
+
chart_items = soup.select("li.o-chart-results-list__item h3")
|
| 53 |
+
artist_items = soup.select("li.o-chart-results-list__item span.c-label")
|
| 54 |
|
| 55 |
+
for i in range(min(10, len(chart_items))):
|
| 56 |
+
song_name = chart_items[i].get_text(strip=True)
|
| 57 |
+
artist_name = artist_items[i * 2].get_text(strip=True) if i * 2 < len(artist_items) else "Unknown Artist"
|
| 58 |
+
top_songs.append({"song": song_name, "artist": artist_name})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
return top_songs
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
|
|
|
| 65 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 66 |
@tool
|
| 67 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|