How to make a holiday calendar step by step

Tired of looking for holidays in your calendar everyday? How about getting all holidays in a single page? This is the guide for you!

How to make a holiday calendar step by step

Have you thought about how many company holidays are available? Do you often check when the next holiday is? Would it be nice to have a calendar full of the holidays for the year? Today we will create a holiday calendar using Python using the Nylas APIs and visualize with Obsidian (A powerful knowledge base). 

What are we going to talk about?

Step 1 – Getting started

To install Python (if you don’t have it installed already), install the Nylas Python SDK, set up the .env file and get your tokens for the dashboard. Also, read the blog post How to Send Emails with the Nylas Python SDK for further details on setup.

To install Obsidian (as we will generate a Markdown file), follow their instructions.

Our .env file will contain the following information:


Step 2 – Creating the Python script

Create a file and call it with the following code:

# Import your dependencies
import os
import sys
import re
import calendar
from datetime import date
import datetime
from nylas import APIClient
from dotenv import load_dotenv

# Load your env variables

# Initialize your Nylas API client
nylas = APIClient(

# Array to hold all events
yearly_events = []
# Months of the year
months = range(1, 13)
# Year that we want to print out
year = str(sys.argv[1])

# Path of file
file_name = (
    "<YOUR_OBSIDIAN_PATH>/Documents/Blag/Holidays Calendar "
    + year
    + ".md"

START_TIME = int(datetime.datetime(int(year), 1, 1, 0, 0, 0).strftime('%s'))
END_TIME = int(datetime.datetime(int(year), 12, 31, 23, 0, 0).strftime('%s'))

# Use RegEx to filter out by year
regex = re.compile(year)

# Get all events from our Holidays Calendar
starts_after = START_TIME, ends_before = END_TIME)

# Store all events in an array
for event in events:
    yearly_events.append(event.when["date"] + " " + event.title)

# Use our RegEx to get only events happening on the requested year
#filtered_events = [event for event in yearly_events if regex.match(event)]
filtered_events = yearly_events

# Open the file to write to it
with open(file_name, "w") as f:
    f.write(f"**Holidays Calendar {year}**\n\n")
    # Loop months to get events for each of them
    for month in months:
        if month < 10:
            s_month = "0" + str(month)
            s_month = str(month)
        # Get only the current month using RegEx
        regex = re.compile(".*-" + s_month + "-.*")
        filtered_month = [event for event in filtered_events if regex.match(event)]
        # Print name of month
        f.write(f"|{calendar.month_name[month]}| |")
        # If we have events for that month, print them out
        if len(filtered_month) > 0:
            for filtered in filtered_month:
                # We want to get the day the event happens
                day = re.findall("(..\s)", filtered)
                # And we want the event title
                event = re.findall("(\s.*)", filtered)
# Close the file

The code is doing the following items:

  1. We are getting the first and last day of the year for the parameter that we will pass to our script.
  2. Then, we will get all events for that time range for our company holidays calendar.
  3. Once we have them, we want to extract the date and title.
  4. Finally, we will create a markdown file with the information we have.

Step 3 – Creating a Holiday Calendar

To create a holiday calendar, we need to run our script passing the year that we want to process:

$ python3 2023

This will create the Holiday Calendar file on our Obsidian installation.

Step 4 – Visualizing our Calendar

If we open Obsidian, we will find the newly created note displaying the holidays for the specified year.

Holiday Calendar

What’s next?

To learn more about Calendars and Events, check our official documentation on Calendars and Events.

Why don’t you sign up Nylas for free and start building!

Don’t miss the action, watch our LiveStream Coding with Nylas:

You May Also Like

How to add Zoom to your event meetings
Nylas_Gartner Cool Vendor
Nylas recognized as a Cool Vendor in the Gartner 2023 Cool Vendors in Composable Customer Engagement Platforms
How to manage your Contacts using Reflex (Pynecone)

Subscribe for our updates

Please enter your email address and receive the latest updates.