Skip to content

Commit

Permalink
Add new years eve countdown
Browse files Browse the repository at this point in the history
  • Loading branch information
rtitmuss committed Dec 31, 2024
1 parent ee27719 commit 689f8a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion micropython/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from provider.ProviderClock import ProviderClock
from provider.ProviderDadJoke import ProviderDadJoke
from provider.ProviderMotion import ProviderMotion
from provider.ProviderNewYearCountdown import ProviderNewYearCountdown
from provider.ProviderLetters import ProviderLetters

# element order when displaying alphabet
Expand All @@ -11,12 +12,13 @@

# flap offsets in display order for calibration
display_offsets = [0, 0, -4, 0, 9, 22, 11, 0, 0, 0,
2, 0, 0, -4, 32, 0, 0, 0, 0, 0]
2, 0, 0, -16, 32, 0, 0, 0, 0, 0]

providers = {
"{CLOCK_STO}": ProviderClock("STO %H:%M%d.%m.%Y", "Europe/Stockholm"),
"{CLOCK_ADL}": ProviderClock("ADL %H:%M%d.%m.%Y", "Australia/Adelaide"),
"{CLOCK_NYC}": ProviderClock("NYC %H:%M%d.%m.%Y", "America/New_York"),
"{NEW_YEAR_STO}": ProviderNewYearCountdown("Europe/Stockholm"),
"{ART}": ProviderArt(),
"{MOTION}": ProviderMotion(),
"{DAD_JOKE}": ProviderDadJoke(),
Expand Down
25 changes: 25 additions & 0 deletions micropython/provider/ProviderNewYearCountdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Union, Tuple

from provider.Clock import Clock
from provider.Provider import Provider


class ProviderNewYearCountdown(Provider):
def __init__(self, timezone: str):
self.timezone = timezone

def get_word(self, word: str, display: Display) -> Tuple[str, Union[int, None]]:
now = Clock.now(self.timezone)

if now.month == 1 and now.day == 1: # Jan 1st
return now.strftime("!HAPPY NEWYEAR %Y!"), None

next_interval_ms = (60 - now.second) * 1000

delta_hours = 23 - now.hour
delta_minutes = 59 - now.minute

if delta_minutes % 2 == 0:
return f"{now.year+1:04} IN {delta_hours:02}:{delta_minutes:02} ", next_interval_ms
else:
return f"COUNT DOWN {delta_hours:02}:{delta_minutes:02} ", next_interval_ms
2 changes: 2 additions & 0 deletions micropython/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
<a href="#" onclick="preset('{clock_adl}', 'start_in_sync')">ADL</a>
<a href="#" onclick="preset('{clock_nyc}', 'start_in_sync')">NYC</a>
<br/>
<a href="#" onclick="preset('{new_year_sto}', 'end_in_sync')">New Year Countdown</a>
<br/>
<a href="#" onclick="preset('{art}', 'end_in_sync')">Art</a>
<br/>
<a href="#" onclick="preset('{motion}', 'start_in_sync')">Motion</a>
Expand Down

0 comments on commit 689f8a8

Please sign in to comment.