From 3f737c2328178858b79d28e6cc1b0750c680d84e Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Thu, 16 Apr 2020 16:37:59 +0200 Subject: [PATCH] Revert UTC changes. This reverts commit 3ebbd4adf67517a8bcffd2bd9ab821b0e5ca5485. --- requirements.ci.txt | 1 - requirements.txt | 2 -- serverconfig.ini.example | 3 --- stateserver.py | 17 ++++++----------- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/requirements.ci.txt b/requirements.ci.txt index e0b686d..b8e826a 100644 --- a/requirements.ci.txt +++ b/requirements.ci.txt @@ -12,7 +12,6 @@ MarkupSafe==1.1.1 multidict==4.7.5 mypy==0.770 mypy-extensions==0.4.3 -pytz==2019.3 requests==2.23.0 typed-ast==1.4.1 typing-extensions==3.7.4.2 diff --git a/requirements.txt b/requirements.txt index 14acc9d..232be3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -32,10 +32,8 @@ pyee==7.0.1 pylibsrtp==0.6.6 pyls==0.1.6 pyls-mypy==0.1.8 -python-dateutil==2.8.1 python-jsonrpc-server==0.3.4 python-language-server==0.31.9 -pytz==2019.3 raygun4py==4.3.0 requests==2.23.0 six==1.14.0 diff --git a/serverconfig.ini.example b/serverconfig.ini.example index 4f323bb..d3a2ce3 100644 --- a/serverconfig.ini.example +++ b/serverconfig.ini.example @@ -2,9 +2,6 @@ key = CHANGEME enable = False -[time] -local_timezone = Europe/London - [shittyserver] notify_url = https://example.com websocket_port = 8079 diff --git a/stateserver.py b/stateserver.py index 105df98..5423d0c 100755 --- a/stateserver.py +++ b/stateserver.py @@ -9,7 +9,6 @@ from flask import Flask, jsonify, request from flask_cors import CORS # type: ignore import requests import datetime -import pytz import random from telnetlib import Telnet import configparser @@ -23,8 +22,6 @@ CORS(app) # Enable Cors access-all SUSTAINER_AUTONEWS = config.get("stateserver", "sustainer_autonews") == "True" -LOCAL_TIME = pytz.timezone(config.get("time", "local_timezone")) - def do_ws_srv_telnet(source: str) -> None: HOST = "localhost" @@ -56,7 +53,7 @@ def myradioApiRequest(url: str) -> Any: def getNextHourTimestamp() -> int: - current = datetime.datetime.utcnow() + current = datetime.datetime.now() currentPlusHour = current + datetime.timedelta(hours=1) nextHourStart = currentPlusHour.replace(minute=0, second=0) nextTimestamp = int(nextHourStart.timestamp()) @@ -88,7 +85,7 @@ lastConnectionIDToRegister = -1 def getCurrentShowConnection() -> Optional[Connection]: for connection in connections: - if (connection["startTimestamp"] <= datetime.datetime.utcnow().timestamp()) and ( + if (connection["startTimestamp"] <= datetime.datetime.now().timestamp()) and ( connection["endTimestamp"] >= getNextHourTimestamp()): return connection return None @@ -114,7 +111,7 @@ def getNextHourConnection() -> Optional[Connection]: def cleanOldConnections() -> None: global connections for i in range(len(connections)): - if connections[i]["endTimestamp"] < datetime.datetime.utcnow().timestamp(): + if connections[i]["endTimestamp"] < datetime.datetime.now().timestamp(): connections.pop(i) @@ -263,14 +260,13 @@ def post_registerCheck() -> Any: return genPayload(conn) start_time = datetime.datetime.strptime(timeslot["start_time"], "%d/%m/%Y %H:%M") - start_time = LOCAL_TIME.localize(start_time).astimezone(pytz.utc) duration = timeslot["duration"].split(":") duration_time = datetime.timedelta(hours=int(duration[0]), minutes=int(duration[1])) end_time = start_time + duration_time - now_time = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) + now_time = datetime.datetime.now() 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.") @@ -290,9 +286,8 @@ def post_registerCheck() -> Any: 'wsid': None } if "wsid" in content: - print("got wsid from client! {}".format(content["wsid"])) connection["wsid"] = content["wsid"] - if start_time + datetime.timedelta(minutes=2) < now_time: + if start_time > now_time + datetime.timedelta(minutes=2): # they're late, bring them live now print("({}, {}) late, bringing on air now".format(connection["connid"], connection["wsid"])) do_ws_srv_telnet(connection["wsid"]) @@ -366,7 +361,7 @@ def post_wsSessions() -> Any: print("({}, {}) hello".format(conn["connid"], conn["wsid"])) if conn["wsid"] in wsids_to_add: - if conn["startTimestamp"] + 120 < datetime.datetime.utcnow().timestamp(): + if conn["startTimestamp"] + 120 < datetime.datetime.now().timestamp(): # they're late, bring them on air now print("({}, {}) late, bringing on air now".format(conn["connid"], conn["wsid"])) do_ws_srv_telnet(conn["wsid"])