-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_app.py
33 lines (23 loc) · 1.02 KB
/
api_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import json
# The purpose of the application is to help a user get the
# list of the holdays in a country in a particular year
# def get_holidays():
# Enter the name of the country. The name should
# follow the (ISO 3166-2 format) like Argentina is AR,
country = input('Enter country(ISO 3166-2 format): ')
# Enter the year for which you want the holidays be displayed
year = input('Enter Year: ')
# Enter the month for which you want the holidays displayed.
month = input('Enter month(1 or 2 digit month(1-12)): ')
api_key = '370b4375-19ea-4f7e-9159-b080786fe326'
get_holidays_request = requests.get('https://holidayapi.com/v1/holidays?key='+api_key+'&country='+country+'&year='+year+'&month='+month)
if(get_holidays_request.status_code==200):
holidays_info = get_holidays_request.json()
if holidays_info['holidays']:
for holiday in holidays_info['holidays']:
print("Date: {}, Name:{}".format(holiday['date'],holiday['name']))
else:
print("No holidays found.")
else:
print("not acceptable country")