mirror of
https://github.com/holidayapi/holidayapi-python.git
synced 2025-06-21 04:16:32 +00:00
make code work with python 3.x
also some minor code refactor
This commit is contained in:
parent
5fabca70a2
commit
15e629786a
1 changed files with 7 additions and 8 deletions
|
@ -2,23 +2,22 @@ import json
|
|||
import requests
|
||||
|
||||
class v1:
|
||||
key = None
|
||||
|
||||
def __init__(self, key):
|
||||
self.key = key
|
||||
|
||||
def holidays(self, parameters):
|
||||
url = 'https://holidayapi.com/v1/holidays?'
|
||||
|
||||
if parameters.has_key('key') is False:
|
||||
if not parameters.get('key'):
|
||||
parameters['key'] = self.key
|
||||
else:
|
||||
assert self.key == parameters['key'], 'keys supplied as an argument & in `parameters` differ. \n Provide at only one place'
|
||||
|
||||
response = requests.get(url, params=parameters);
|
||||
data = json.loads(response.text)
|
||||
data = response.json()
|
||||
|
||||
if response.status_code != 200:
|
||||
if data.has_key('error') is False:
|
||||
if not response.ok:
|
||||
if not data.get('error'):
|
||||
data['error'] = 'Unknown error.'
|
||||
|
||||
return data
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue