Skip to content

Instantly share code, notes, and snippets.

@flutefreak7
Last active January 18, 2024 06:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flutefreak7/53f7b36baaa122cfbfe18ebf83b6f0e3 to your computer and use it in GitHub Desktop.
Save flutefreak7/53f7b36baaa122cfbfe18ebf83b6f0e3 to your computer and use it in GitHub Desktop.
Make an HTML calendar in a Notebook and highlight some days...
# intended for use in a Jupyter Notebook or similar.
import calendar
from calendar import HTMLCalendar
from IPython.display import HTML
# Based on https://stackoverflow.com/a/1458077/1639671
class HighlightedCalendar(HTMLCalendar):
def __init__(self, highlight=[], *args, **kwargs):
super().__init__(*args, **kwargs)
self._highlight = highlight
def formatday(self, day, weekday):
"""
Return a day as a table cell.
"""
if day in self._highlight:
return '<td class="%s" bgcolor="pink">%d</td>' % (self.cssclasses[weekday], day)
else:
return super().formatday(day, weekday)
highlight = range(1, 7)
HTML(HighlightedCalendar(highlight=highlight).formatmonth(2018, 11))
@kvshravan
Copy link

Great work! Super helpful...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment