Skip to content

Instantly share code, notes, and snippets.

@martin-kokos
Last active December 21, 2018 13:35
Show Gist options
  • Save martin-kokos/4a031f5009e115fda2d84e83b1c0449d to your computer and use it in GitHub Desktop.
Save martin-kokos/4a031f5009e115fda2d84e83b1c0449d to your computer and use it in GitHub Desktop.
Advent countdown
import datetime as dt
from time import sleep as s
curr_date = dt.datetime.now().replace(month=11,day=27)
class Candles(list):
def __repr__(self):
items = ['\N{CANDLE}' if i else '_' for i in self]
return '[{items}]'.format(items=', '.join(items))
candles = Candles([False]*4)
v = dt.datetime.now().replace(month=12,day=24)
n = v - dt.timedelta(v.isoweekday()%7)
while not all(candles):
left = (n - curr_date).days
if not left/7 % 1 and left/7 < 4:
candles[int((4-left/7)-1)] = True
print(f'{curr_date:%Y-%m-%d} {candles}', end='\n\n')
curr_date += dt.timedelta(1); s(0.1)
else:
print('Merry Christmas!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment