Last active
January 18, 2024 06:59
-
-
Save flutefreak7/53f7b36baaa122cfbfe18ebf83b6f0e3 to your computer and use it in GitHub Desktop.
Make an HTML calendar in a Notebook and highlight some days...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great work! Super helpful...