1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-13 19:42:20 -05:00
SickRage/lib/trakt/__init__.py

20 lines
690 B
Python
Raw Normal View History

2014-11-20 07:40:33 -05:00
import hashlib
import requests
def TraktCall(method, api, username=None, password=None, data={}):
2014-11-20 07:40:33 -05:00
base_url = 'http://api.trakt.tv/'
2014-11-20 07:40:33 -05:00
# if username and password given then encode password with sha1
auth = None
if username and password:
2014-11-20 07:40:33 -05:00
auth = (username, hashlib.sha1(password.encode('utf-8')).hexdigest())
# request the URL from trakt and parse the result as json
try:
2014-11-20 07:40:33 -05:00
resp = requests.get(base_url + method.replace("%API%", api), auth=auth, data=data).json()
if isinstance(resp, dict) and resp.get('status', False) == 'failure':
raise Exception(resp.get('error', 'Unknown Error'))
except:
return None
return resp