-
Notifications
You must be signed in to change notification settings - Fork 0
/
fipradio.py
37 lines (32 loc) · 872 Bytes
/
fipradio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
import time
import subprocess
URL = 'http://www.fipradio.fr/livemeta/7'
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 = "{title} — {authors} ({anneeEditionMusique})".format(**data)
msg2 = msg.title()
print(msg2)
subprocess.Popen(['toot', 'post', msg2])
last_data = data
time.sleep(10)
if __name__ == '__main__':
import traceback
try:
main()
except:
with open('/tmp/fip-crash.log', 'w') as f:
traceback.print_exc(file=f)