Skip to content

Instantly share code, notes, and snippets.

@henrydatei
Created August 1, 2023 12:55
Show Gist options
  • Save henrydatei/89add286c339b489817fb7303934cd9f to your computer and use it in GitHub Desktop.
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
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