-
Notifications
You must be signed in to change notification settings - Fork 0
/
london_commute_alert.py
41 lines (30 loc) · 1.06 KB
/
london_commute_alert.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
38
39
40
41
import datetime
import os
import requests
import sys
def update(lines):
url = 'http://api.tfl.gov.uk/Line/Mode/tube/Status'
resp = requests.get(url).json()
result = []
for el in resp:
value = el['lineStatuses'][0]
state = value['statusSeverityDescription']
if el['id'] in lines and state != 'Good Service':
result.append('{}: {} ({})'.format(
el['id'].capitalize(), state, value['reason']))
return result
def email(delays):
# While tube is on shuttle service, don't email
return
os.chdir(sys.path[0])
with open('curl_raw_command.sh') as f:
raw_command = f.read()
# Running on PythonAnywhere - Monday to Sunday. Skip on the weekend
if delays and datetime.date.today().isoweekday() in range(1, 6):
os.system(raw_command.format(subject='Tube delays for commute',
body='\n\n'.join(delays)))
def main():
commute_lines = ['metropolitan', 'jubilee', 'central']
email(update(commute_lines))
if __name__ == '__main__':
main()