Holidays with Python

With this code you will know the holidays in your country.

First of all, let’s install the module holidays from the python interpreter (you can do it from the cmd too with just pip install holidays).

import os

os.system("pip install holidays")

This are the countries of which you can know the holidays:

‘APR’, ‘AR’, ‘AT’, ‘AU’, ‘AUG’, ‘Argentina’, ‘Australia’, ‘Austria’, ‘BE’, ‘BR’, ‘BY’, ‘Belarus’, ‘Belgium’, ‘Brazil’, ‘CA’, ‘CH’, ‘CO’, ‘CZ’, ‘Canada’, ‘Colombia’, ‘CountryHoliday’, ‘Croatia’, ‘Czech’, ‘DE’, ‘DEC’, ‘DK’, ‘Denmark’, ‘EASTER_ORTHODOX’, ‘ECB’, ‘ES’, ‘England’, ‘EuropeanCentralBank’, ‘FEB’, ‘FI’, ‘FR’, ‘FRA’, ‘FRI’, ‘Finland’, ‘France’, ‘Germany’, ‘HND’, ‘HR’, ‘HU’, ‘HolidayBase’, ‘Honduras’, ‘Hungary’, ‘IE’, ‘IND’, ‘IT’, ‘India’, ‘Ireland’, ‘IsleOfMan’, ‘Italy’, ‘JAN’, ‘JP’, ‘JUL’, ‘JUN’, ‘Japan’, ‘MAR’, ‘MAY’, ‘MO’, ‘MON’, ‘MX’, ‘Mexico’, ‘NL’, ‘NO’, ‘NOV’, ‘NZ’, ‘Netherlands’, ‘NewZealand’, ‘NorthernIreland’, ‘Norway’, ‘OCT’, ‘PL’, ‘PT’, ‘PTE’, ‘Polish’, ‘Portugal’, ‘PortugalExt’, ‘SA’, ‘SAT’, ‘SE’, ‘SEP’, ‘SI’, ‘SK’, ‘SU’, ‘SUN’, ‘Scotland’, ‘Slovak’, ‘Slovenia’, ‘SouthAfrica’, ‘Spain’, ‘Sweden’, ‘Switzerland’, ‘TAR’, ‘TH’, ‘THU’, ‘TU’, ‘TUE’, ‘UA’, ‘UK’, ‘US’, ‘Ukraine’, ‘UnitedKingdom’, ‘UnitedStates’, ‘WE’, ‘WED’, ‘WEEKEND’, ‘Wales’, ‘ZA’

Now, let’s see in Italy:

>>> import holidays
>>> for holiday in holidays.IT(years=2019).items():
...     print(holiday)
...
(datetime.date(2019, 1, 1), 'Capodanno')
(datetime.date(2019, 1, 6), 'Epifania del Signore')
(datetime.date(2019, 4, 21), 'Pasqua di Resurrezione')
(datetime.date(2019, 4, 22), "Lunedì dell'Angelo")
(datetime.date(2019, 4, 25), 'Festa della Liberazione')
(datetime.date(2019, 5, 1), 'Festa dei Lavoratori')
(datetime.date(2019, 6, 2), 'Festa della Repubblica')
(datetime.date(2019, 8, 15), 'Assunzione della Vergine')
(datetime.date(2019, 11, 1), 'Tutti i Santi')
(datetime.date(2019, 12, 8), 'Immacolata Concezione')
(datetime.date(2019, 12, 25), 'Natale')
(datetime.date(2019, 12, 26), 'Santo Stefano')

 

 

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.