Day 1 of Hanukkah at Anvil
Build a web app for each night of Hanukkah, with nothing but Python!
Introducing How Many Candles!
We’re busy people - sometimes it’s hard to keep track of how many candles to light each night of the holiday. Not to mention the blessings and which direction to light in.
Instead of Googling it each time, I decided to write myself an app!
Not only does it tell you how many candles to light, but you also get the text of the right blessings for each day, leaving you more time to enjoy donuts!
Using HTTP Requests
HebCal is a handy date converter and calendar that will tell you when the Jewish holidays are. Using Anvil’s HTTP Requests function, I set up a quick HebCal query to check whether it’s Hanukkah today (and if so, which night).
@anvil.server.callable
def is_hanukkah():
"""
Queries HebCal API for data on which Jewish date it is today
"""
today = date.today() # Find out today's date
result = anvil.http.request("https://www.hebcal.com/converter?cfg=json&gy={}&gm={}&gd={}&g2h=1".format(today.year, today.month, today.day), json=True)
for event in result['events']:
m = re.match('^Chanukah:[\s]*([0-9])[\s]*Candle[s]?', event)
if m:
# There is a match, so it's Hanukkah, return what night it is
n_night = m.group(1)
return int(n_night)
return False
I used a regular expression and Python’s re
library to parse the results and check whether the word “Chanukah” appears. (There are a lot of potential spellings for this holiday! This is the one HebCal uses).
Email updates
Finally, I added a sign-up button that uses Anvil’s Email Service to send users a daily reminder email for how many candles they should light that night.
There’s a custom unsubscribe link for every signed-up user that they can click from within their email if they’d like to opt out. This email unsubscribe code was shamelessly stolen from my Fruitmoji app - so take a look at that if you’d like to learn more about how it all works under the hood!
Give the Gift of Python
Share this post:
Get tomorrow's app in your inbox
Don't miss a day! We'll mail you a new web app every night of Hanukkah: