Created
February 4, 2024 14:46
-
-
Save wturrell/f887b3d413339597b35549293f1bad63 to your computer and use it in GitHub Desktop.
FIP Radio now playing list
This file contains hidden or 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
# Displays the currently playing media at FIP radio | |
# http://www.fipradio.fr/player | |
# You may want to update the number at the end of the URL | |
# if you use a specific "style" channel instead of the | |
# generic (main) channel, which is 7. | |
import requests | |
import time | |
import subprocess | |
from datetime import datetime | |
URL = 'https://api.radiofrance.fr/livemeta/pull/7' | |
print("FIP Radio - Now Playing...") | |
def retrieve(): | |
data = requests.get(URL).json() | |
level = data['levels'][0] | |
uid = level['items'][level['position']] | |
step = data['steps'][uid] | |
return step | |
def main(): | |
last_data = None | |
while True: | |
try: | |
data = retrieve() | |
except Exception: | |
time.sleep(2) | |
continue | |
if data != last_data: | |
msg = datetime.now().strftime('%a %H:%M') + " {title} — {authors} ({anneeEditionMusique})".format(**data) | |
print(msg) | |
#subprocess.check_call(['notify-send', '-i', 'applications-multimedia', 'FIP radio', | |
# msg]) | |
last_data = data | |
time.sleep(20) | |
if __name__ == '__main__': | |
import traceback | |
try: | |
main() | |
except: | |
with open('/tmp/fip-crash.log', 'w') as f: | |
traceback.print_exc(file=f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment