mirror of
https://github.com/Kunsi/scheduled-plugin-pretalx-broadcast-tools.git
synced 2024-11-25 11:31:04 +00:00
service: even more timezones, and a bit of formatting
This commit is contained in:
parent
cc9b565b8e
commit
17992f7283
1 changed files with 14 additions and 15 deletions
29
service
29
service
|
@ -20,10 +20,7 @@ def idle(seconds, event_start, event_tz):
|
||||||
end = time.time() + seconds
|
end = time.time() + seconds
|
||||||
log("sleeping for {} seconds".format(seconds))
|
log("sleeping for {} seconds".format(seconds))
|
||||||
while time.time() < end:
|
while time.time() < end:
|
||||||
send_data = {
|
send_data = {"day": "??", "time": time.time()}
|
||||||
'day': '??',
|
|
||||||
'time': time.time()
|
|
||||||
}
|
|
||||||
if event_start is not None:
|
if event_start is not None:
|
||||||
event_now = datetime.now(event_tz)
|
event_now = datetime.now(event_tz)
|
||||||
utc_now = datetime.now(pytz.utc)
|
utc_now = datetime.now(pytz.utc)
|
||||||
|
@ -31,10 +28,7 @@ def idle(seconds, event_start, event_tz):
|
||||||
utc_offset = (event_now - utc_now).total_seconds()
|
utc_offset = (event_now - utc_now).total_seconds()
|
||||||
|
|
||||||
day_zero = event_start.replace(
|
day_zero = event_start.replace(
|
||||||
hour=0,
|
hour=0, minute=0, second=0, tzinfo=event_tz
|
||||||
minute=0,
|
|
||||||
second=0,
|
|
||||||
tzinfo=timezone
|
|
||||||
) - timedelta(days=1)
|
) - timedelta(days=1)
|
||||||
|
|
||||||
day_info = event_now - day_zero
|
day_info = event_now - day_zero
|
||||||
|
@ -42,11 +36,11 @@ def idle(seconds, event_start, event_tz):
|
||||||
log("Day0: {}".format(day_zero.isoformat()))
|
log("Day0: {}".format(day_zero.isoformat()))
|
||||||
log("NOW: {}".format(event_now.isoformat()))
|
log("NOW: {}".format(event_now.isoformat()))
|
||||||
|
|
||||||
send_data['day'] = day_info.days
|
send_data["day"] = day_info.days
|
||||||
|
|
||||||
for k,v in send_data.items():
|
for k, v in send_data.items():
|
||||||
node.send_raw('root/plugin/pretalx/{}:{}'.format(k, v))
|
node.send_raw("root/plugin/pretalx/{}:{}".format(k, v))
|
||||||
node.send_raw('root/plugin/pretalx-broadcast-tools/{}:{}'.format(k, v))
|
node.send_raw("root/plugin/pretalx-broadcast-tools/{}:{}".format(k, v))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +79,7 @@ def main():
|
||||||
|
|
||||||
if event_info is not None:
|
if event_info is not None:
|
||||||
event_start = datetime.strptime(event_info["start"], "%Y-%m-%d")
|
event_start = datetime.strptime(event_info["start"], "%Y-%m-%d")
|
||||||
event_tz = pytz.timezone(event_info['timezone'])
|
event_tz = pytz.timezone(event_info["timezone"])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = get(
|
r = get(
|
||||||
|
@ -99,8 +93,13 @@ def main():
|
||||||
# we need.
|
# we need.
|
||||||
else:
|
else:
|
||||||
schedule = r.json()
|
schedule = r.json()
|
||||||
for talk in schedule['talks']:
|
for talk in schedule["talks"]:
|
||||||
talk['start_str'] = datetime.fromtimestamp(talk['start_ts']).replace(tzinfo=pytz.utc).astimezone(event_tz).strftime('%H:%M')
|
talk["start_str"] = (
|
||||||
|
datetime.fromtimestamp(talk["start_ts"])
|
||||||
|
.replace(tzinfo=pytz.utc)
|
||||||
|
.astimezone(event_tz)
|
||||||
|
.strftime("%H:%M")
|
||||||
|
)
|
||||||
node.write_json("schedule.json", schedule)
|
node.write_json("schedule.json", schedule)
|
||||||
log("updated schedule json")
|
log("updated schedule json")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue