Fix bad error code handling

master
LEdoian 8 months ago
parent 3b4f07663b
commit ddc560a4ae

@ -7,6 +7,7 @@ from datetime import datetime
from dataclasses import dataclass
from collections import defaultdict
from pathlib import Path
import sys
api_url = r'https://review.video.fosdem.org/api/v1/event/1/overview'
poll_rate = 10*60 # seconds
@ -21,7 +22,7 @@ class TimeSeries:
def get_data() -> tuple[datetime, dict[str, int], dict[str, int]]:
resp = requests.get(api_url)
# TODO: error handling?
if resp.status_code != 200: raise RuntimeError(f'bad status code: {resp.status_code}')
time = datetime.now().astimezone()
data = json.loads(resp.content.decode())
states = defaultdict(lambda: 0)
@ -46,12 +47,16 @@ def main():
plt.show(block=False)
while True:
try:
time, states, jobstates = get_data()
print(f'data got at {time}')
assert time not in ts.data
ts.data[time] = (states, jobstates)
ts.states |= states.keys()
ts.jobstates |= jobstates.keys()
except RuntimeError as e:
print('Could not get/save data.')
sys.print_exc()
# Save the pickle
# Should probably save elsewhere and do atomic rename, but whatever.

Loading…
Cancel
Save