Write reply to disk on error
This commit is contained in:
parent
08a1b5cd96
commit
bcdc8d29b0
11
monitor.py
11
monitor.py
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python3.6
|
||||
import requests
|
||||
import json
|
||||
from typing import List
|
||||
@ -33,6 +33,8 @@ class MOT:
|
||||
ALL_MODES = [LONG_DISTANCE_TRAIN, REGIONAL_TRAIN, COMMUTER_TRAIN, UNDERGROUND_TRAIN, TRAM, BUS, ELEVATED_TRAIN]
|
||||
|
||||
|
||||
last_reply = requests.Response
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-s", "--setup", help="Run the setup routine.", action="store_true", dest="setup")
|
||||
|
||||
@ -144,6 +146,7 @@ def make_request_data(station_id: int, result_count: int = 8, modes: List = MOT.
|
||||
def get_data(request_data: dict, headers: dict = None, cookies: dict = None) -> dict:
|
||||
url = 'https://abfahrtsmonitor.vrr.de/backend/api/stations/table'
|
||||
reply = HTTP.post(url, data=request_data, headers=headers, cookies=cookies)
|
||||
last_reply = reply
|
||||
reply.raise_for_status()
|
||||
print('Request time elapsed: ' + str(reply.elapsed), file=sys.stderr)
|
||||
return reply.json()
|
||||
@ -301,7 +304,13 @@ def main():
|
||||
cursor = cxn.cursor()
|
||||
cursor.execute(TABLE)
|
||||
|
||||
try:
|
||||
wait(cxn, USE_STATION_ID)
|
||||
except (ValueError, TypeError) as e:
|
||||
with open("fault.json", "wb") as o:
|
||||
if last_reply is not None:
|
||||
o.write(last_reply.content) # requests.Response.content is a ByteIO
|
||||
raise e
|
||||
|
||||
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user