Revert UTC changes.

This reverts commit 3ebbd4adf6.
This commit is contained in:
Marks Polakovs 2020-04-16 16:37:59 +02:00
parent e6bdb1b1a7
commit 3f737c2328
4 changed files with 6 additions and 17 deletions

View file

@ -12,7 +12,6 @@ MarkupSafe==1.1.1
multidict==4.7.5 multidict==4.7.5
mypy==0.770 mypy==0.770
mypy-extensions==0.4.3 mypy-extensions==0.4.3
pytz==2019.3
requests==2.23.0 requests==2.23.0
typed-ast==1.4.1 typed-ast==1.4.1
typing-extensions==3.7.4.2 typing-extensions==3.7.4.2

View file

@ -32,10 +32,8 @@ pyee==7.0.1
pylibsrtp==0.6.6 pylibsrtp==0.6.6
pyls==0.1.6 pyls==0.1.6
pyls-mypy==0.1.8 pyls-mypy==0.1.8
python-dateutil==2.8.1
python-jsonrpc-server==0.3.4 python-jsonrpc-server==0.3.4
python-language-server==0.31.9 python-language-server==0.31.9
pytz==2019.3
raygun4py==4.3.0 raygun4py==4.3.0
requests==2.23.0 requests==2.23.0
six==1.14.0 six==1.14.0

View file

@ -2,9 +2,6 @@
key = CHANGEME key = CHANGEME
enable = False enable = False
[time]
local_timezone = Europe/London
[shittyserver] [shittyserver]
notify_url = https://example.com notify_url = https://example.com
websocket_port = 8079 websocket_port = 8079

View file

@ -9,7 +9,6 @@ from flask import Flask, jsonify, request
from flask_cors import CORS # type: ignore from flask_cors import CORS # type: ignore
import requests import requests
import datetime import datetime
import pytz
import random import random
from telnetlib import Telnet from telnetlib import Telnet
import configparser import configparser
@ -23,8 +22,6 @@ CORS(app) # Enable Cors access-all
SUSTAINER_AUTONEWS = config.get("stateserver", "sustainer_autonews") == "True" 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: def do_ws_srv_telnet(source: str) -> None:
HOST = "localhost" HOST = "localhost"
@ -56,7 +53,7 @@ def myradioApiRequest(url: str) -> Any:
def getNextHourTimestamp() -> int: def getNextHourTimestamp() -> int:
current = datetime.datetime.utcnow() current = datetime.datetime.now()
currentPlusHour = current + datetime.timedelta(hours=1) currentPlusHour = current + datetime.timedelta(hours=1)
nextHourStart = currentPlusHour.replace(minute=0, second=0) nextHourStart = currentPlusHour.replace(minute=0, second=0)
nextTimestamp = int(nextHourStart.timestamp()) nextTimestamp = int(nextHourStart.timestamp())
@ -88,7 +85,7 @@ lastConnectionIDToRegister = -1
def getCurrentShowConnection() -> Optional[Connection]: def getCurrentShowConnection() -> Optional[Connection]:
for connection in connections: for connection in connections:
if (connection["startTimestamp"] <= datetime.datetime.utcnow().timestamp()) and ( if (connection["startTimestamp"] <= datetime.datetime.now().timestamp()) and (
connection["endTimestamp"] >= getNextHourTimestamp()): connection["endTimestamp"] >= getNextHourTimestamp()):
return connection return connection
return None return None
@ -114,7 +111,7 @@ def getNextHourConnection() -> Optional[Connection]:
def cleanOldConnections() -> None: def cleanOldConnections() -> None:
global connections global connections
for i in range(len(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) connections.pop(i)
@ -263,14 +260,13 @@ def post_registerCheck() -> Any:
return genPayload(conn) return genPayload(conn)
start_time = datetime.datetime.strptime(timeslot["start_time"], "%d/%m/%Y %H:%M") 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 = timeslot["duration"].split(":")
duration_time = datetime.timedelta(hours=int(duration[0]), minutes=int(duration[1])) duration_time = datetime.timedelta(hours=int(duration[0]), minutes=int(duration[1]))
end_time = start_time + duration_time 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): 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.")
@ -290,9 +286,8 @@ def post_registerCheck() -> Any:
'wsid': None 'wsid': None
} }
if "wsid" in content: if "wsid" in content:
print("got wsid from client! {}".format(content["wsid"]))
connection["wsid"] = 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 # they're late, bring them live now
print("({}, {}) late, bringing on air now".format(connection["connid"], connection["wsid"])) print("({}, {}) late, bringing on air now".format(connection["connid"], connection["wsid"]))
do_ws_srv_telnet(connection["wsid"]) do_ws_srv_telnet(connection["wsid"])
@ -366,7 +361,7 @@ def post_wsSessions() -> Any:
print("({}, {}) hello".format(conn["connid"], conn["wsid"])) print("({}, {}) hello".format(conn["connid"], conn["wsid"]))
if conn["wsid"] in wsids_to_add: 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 # they're late, bring them on air now
print("({}, {}) late, bringing on air now".format(conn["connid"], conn["wsid"])) print("({}, {}) late, bringing on air now".format(conn["connid"], conn["wsid"]))
do_ws_srv_telnet(conn["wsid"]) do_ws_srv_telnet(conn["wsid"])