v0.1
This commit is contained in:
50
nporadio2/__main__.py
Normal file
50
nporadio2/__main__.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import sys
|
||||
import requests
|
||||
|
||||
from time import sleep
|
||||
|
||||
|
||||
from radiotrack import RadioTrack
|
||||
from notifications import SongNotification
|
||||
|
||||
|
||||
def get_current_song():
|
||||
result = requests.get(
|
||||
"https://www.nporadio2.nl/api/miniplayer/info?channel=npo-radio-2"
|
||||
)
|
||||
|
||||
data = result.json()
|
||||
radio_tracks = data["data"]["radio_track_plays"]["data"][0]["radio_tracks"]
|
||||
track = RadioTrack(radio_tracks)
|
||||
return track
|
||||
|
||||
|
||||
def putchar(char):
|
||||
print(char, end="")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
un = SongNotification()
|
||||
previous = None
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
track = get_current_song()
|
||||
except requests.exceptions.SSLError:
|
||||
putchar(",")
|
||||
continue
|
||||
|
||||
if previous != track:
|
||||
print(f"\nNew track: {track}")
|
||||
track.save_image()
|
||||
un.notify_song(track)
|
||||
else:
|
||||
putchar(".")
|
||||
|
||||
previous = track
|
||||
|
||||
sleep(10)
|
||||
except KeyboardInterrupt:
|
||||
print("\nBye!")
|
||||
Reference in New Issue
Block a user