Created
August 1, 2023 12:55
-
-
Save henrydatei/89add286c339b489817fb7303934cd9f to your computer and use it in GitHub Desktop.
Analyse what Energy Sachsen (a radio broadcast station) has played via their API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
import requests | |
def getTotalSongLength(day, hour): | |
dauer = 0 | |
params = {"day": day, "hour": hour} | |
req = requests.get("https://api.nrjnet.de/webradio/playlist/energy/sachsen", params = params) | |
req.raise_for_status() | |
for title in req.json()["playlist"]["songs"]: | |
duration = title["duration"].split(":") | |
dauer = dauer + int(duration[0])*60 + int(duration[1]) | |
return dauer/60 | |
#for hour in range(24): | |
# print(hour, getTotalSongLength(-1,hour)) | |
def getSongs(day, hour): | |
liste = [] | |
params = {"day": day, "hour": hour} | |
req = requests.get("https://api.nrjnet.de/webradio/playlist/energy/sachsen", params = params) | |
req.raise_for_status() | |
for title in req.json()["playlist"]["songs"]: | |
song = title["artist"] + " - " + title["title"] | |
liste.append(song) | |
return liste | |
songs = [] | |
for hour in range(24): | |
songs.extend(getSongs(-1, hour)) | |
print(len(songs)) | |
print(len(Counter(songs))) | |
print(Counter(songs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment