first commit

This commit is contained in:
Christian Lawson-Perfect 2025-02-09 20:35:44 +00:00
commit 3f68f9ae72
25 changed files with 8803 additions and 0 deletions

31
cgi-bin/platform_data.py Executable file
View file

@ -0,0 +1,31 @@
#!/srv/think.somethingorotherwhatever.com/venv/bin/python
import cgi
import cgitb
import requests
from pathlib import Path
from datetime import datetime, timedelta
import getpass
cgitb.enable()
form = cgi.FieldStorage()
print('Content-Type: application/json\n')
station = form['station'].value
platform = form['platform'].value
data_root = Path('..') / 'platform_data'
data_root.mkdir(exist_ok=True)
fname = data_root / f'{station}-{platform}.json'
if (not fname.exists()) or (datetime.now() - datetime.fromtimestamp(fname.stat().st_mtime) > timedelta(minutes=1)):
req = requests.get(f'https://metro-rti.nexus.org.uk/api/times/{station}/{platform}')
with open(fname, 'w') as f:
f.write(req.text)
with open(fname) as f:
print(f.read())