- upcoming_countdown_events = self.countdown_events[:12]
- now = datetime.datetime.now()
- count = 0
- timestamps = { }
- for event in upcoming_countdown_events:
- eventstamp = event.start_time
- delta = eventstamp - now
- name = event.friendly_name()
- x = int(delta.total_seconds())
- if x > 0:
- identifier = "id%d" % count
- days = divmod(x, constants.seconds_per_day)
- hours = divmod(days[1], constants.seconds_per_hour)
- minutes = divmod(hours[1], constants.seconds_per_minute)
- g.write('<li><SPAN id="%s">%d days, %02d:%02d</SPAN> until %s</li>\n' % (identifier, days[0], hours[0], minutes[0], name))
- timestamps[identifier] = time.mktime(eventstamp.timetuple())
- count += 1
- self.debug_print("countdown to %s is %dd %dh %dm" % (
- name, days[0], hours[0], minutes[0]))
- g.write('</ul>')
- g.write('<SCRIPT>\nlet timestampMap = new Map([')
- for x in timestamps.keys():
- g.write(' ["%s", %f],\n' % (x, timestamps[x] * 1000.0))
- g.write(']);\n\n')
- g.write("""
+ with file_writer.file_writer("countdown_3_7200.html") as g:
+ g.write("<h1>Countdowns:</h1><hr><ul>\n")
+ now = datetime.datetime.now(pytz.timezone("US/Pacific"))
+ upcoming_countdown_events = self.countdown_events[:12]
+ count = 0
+ timestamps = {}
+ for event in upcoming_countdown_events:
+ eventstamp = event.start_time
+ if eventstamp is None:
+ return False
+ name = event.friendly_name()
+ delta = eventstamp - now
+ x = int(delta.total_seconds())
+ if x > 0:
+ identifier = "id%d" % count
+ days = divmod(x, kiosk_constants.seconds_per_day)
+ hours = divmod(days[1], kiosk_constants.seconds_per_hour)
+ minutes = divmod(hours[1], kiosk_constants.seconds_per_minute)
+ g.write(
+ f'<li><SPAN id="%s">%d days, %02d:%02d</SPAN> until %s</li>\n'
+ % (
+ identifier,
+ int(days[0]),
+ int(hours[0]),
+ int(minutes[0]),
+ name,
+ )
+ )
+ timestamps[identifier] = time.mktime(eventstamp.timetuple())
+ count += 1
+ logger.debug(
+ "countdown to %s is %dd %dh %dm"
+ % (name, days[0], hours[0], minutes[0])
+ )
+ g.write("</ul>")
+ g.write("<SCRIPT>\nlet timestampMap = new Map([")
+ for _ in list(timestamps.keys()):
+ g.write(f' ["{_}", {timestamps[_] * 1000.0}],\n')
+ g.write("]);\n\n")
+ g.write(
+ """