Or, you know, write sensible code.

This commit is contained in:
Marks Polakovs 2020-04-17 10:17:06 +02:00
parent c00efa0884
commit ffa2895157

View file

@ -263,20 +263,14 @@ def post_registerCheck() -> Any:
now_time = datetime.datetime.now() now_time = datetime.datetime.now()
connection: Optional[Connection] = None
for conn in connections: for conn in connections:
if content["timeslotid"] == conn["timeslotid"]: if content["timeslotid"] == conn["timeslotid"]:
# they've already registered, return the existing session # they've already registered, return the existing session
# but first, check if it has a nulled-out wsID print("found existing connection {} for {}".format(conn["connid"], conn["timeslotid"]))
# TODO: duplicate of fragment below connection = conn
if "wsid" in content:
conn["wsid"] = content["wsid"]
if start_time + datetime.timedelta(minutes=2) < now_time:
# they're late, bring them live now
print("({}, {}) rejoined late, bringing on air now".format(conn["connid"], conn["wsid"]))
do_ws_srv_telnet(conn["wsid"])
subprocess.Popen(['sel', '5'])
return genPayload(conn)
if connection is None:
if start_time - now_time > datetime.timedelta(hours=1): if start_time - now_time > datetime.timedelta(hours=1):
return genFail("This show too far away, please try again within an hour of starting your show.") return genFail("This show too far away, please try again within an hour of starting your show.")
@ -298,6 +292,7 @@ def post_registerCheck() -> Any:
'autoNewsEnd': True, 'autoNewsEnd': True,
'wsid': None 'wsid': None
} }
if "wsid" in content: if "wsid" in content:
connection["wsid"] = content["wsid"] connection["wsid"] = content["wsid"]
if start_time + datetime.timedelta(minutes=2) < now_time: if start_time + datetime.timedelta(minutes=2) < now_time:
@ -306,6 +301,7 @@ def post_registerCheck() -> Any:
do_ws_srv_telnet(connection["wsid"]) do_ws_srv_telnet(connection["wsid"])
subprocess.Popen(['sel', '5']) subprocess.Popen(['sel', '5'])
assert connection is not None
connections.append(connection) connections.append(connection)
print(connections) print(connections)