Update TMDB api
This commit is contained in:
1 parent
f22778aacb
commit
a1c0b000a4
12 files changed
+797
-450
No files matched your search
+21
-14
@@ -11,7 +11,7 @@
|
||||
from datetime import datetime as _pydatetime, \
|
||||
tzinfo as _pytzinfo
|
||||
import re
|
||||
class datetime( _pydatetime ):
|
||||
class datetime(_pydatetime):
|
||||
"""Customized datetime class with ISO format parsing."""
|
||||
_reiso = re.compile('(?P<year>[0-9]{4})'
|
||||
'-(?P<month>[0-9]{1,2})'
|
||||
@@ -27,21 +27,27 @@ class datetime( _pydatetime ):
|
||||
'(?P<tzmin>[0-9]{2})?'
|
||||
')?')
|
||||
|
||||
class _tzinfo( _pytzinfo):
|
||||
class _tzinfo(_pytzinfo):
|
||||
def __init__(self, direc='+', hr=0, min=0):
|
||||
if direc == '-':
|
||||
hr = -1*int(hr)
|
||||
self._offset = timedelta(hours=int(hr), minutes=int(min))
|
||||
def utcoffset(self, dt): return self._offset
|
||||
def tzname(self, dt): return ''
|
||||
def dst(self, dt): return timedelta(0)
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return self._offset
|
||||
|
||||
def tzname(self, dt):
|
||||
return ''
|
||||
|
||||
def dst(self, dt):
|
||||
return timedelta(0)
|
||||
|
||||
@classmethod
|
||||
def fromIso(cls, isotime, sep='T'):
|
||||
match = cls._reiso.match(isotime)
|
||||
if match is None:
|
||||
raise TypeError("time data '%s' does not match ISO 8601 format" \
|
||||
% isotime)
|
||||
raise TypeError("time data '%s' does not match ISO 8601 format"
|
||||
% isotime)
|
||||
|
||||
dt = [int(a) for a in match.groups()[:5]]
|
||||
if match.group('sec') is not None:
|
||||
@@ -52,9 +58,9 @@ class datetime( _pydatetime ):
|
||||
if match.group('tz') == 'Z':
|
||||
tz = cls._tzinfo()
|
||||
elif match.group('tzmin'):
|
||||
tz = cls._tzinfo(*match.group('tzdirec','tzhour','tzmin'))
|
||||
tz = cls._tzinfo(*match.group('tzdirec', 'tzhour', 'tzmin'))
|
||||
else:
|
||||
tz = cls._tzinfo(*match.group('tzdirec','tzhour'))
|
||||
tz = cls._tzinfo(*match.group('tzdirec', 'tzhour'))
|
||||
dt.append(0)
|
||||
dt.append(tz)
|
||||
return cls(*dt)
|
||||
@@ -64,10 +70,12 @@ from tmdb_exceptions import *
|
||||
|
||||
syssession = None
|
||||
|
||||
|
||||
def set_session(sessionid):
|
||||
global syssession
|
||||
syssession = Session(sessionid)
|
||||
|
||||
|
||||
def get_session(sessionid=None):
|
||||
global syssession
|
||||
if sessionid:
|
||||
@@ -77,8 +85,8 @@ def get_session(sessionid=None):
|
||||
else:
|
||||
return Session.new()
|
||||
|
||||
class Session( object ):
|
||||
|
||||
class Session(object):
|
||||
@classmethod
|
||||
def new(cls):
|
||||
return cls(None)
|
||||
@@ -91,9 +99,9 @@ class Session( object ):
|
||||
if self._sessionid is None:
|
||||
if self._authtoken is None:
|
||||
raise TMDBError("No Auth Token to produce Session for")
|
||||
# TODO: check authtokenexpiration against current time
|
||||
req = Request('authentication/session/new', \
|
||||
request_token=self._authtoken)
|
||||
# TODO: check authtoken expiration against current time
|
||||
req = Request('authentication/session/new',
|
||||
request_token=self._authtoken)
|
||||
req.lifetime = 0
|
||||
dat = req.readJSON()
|
||||
if not dat['success']:
|
||||
@@ -128,4 +136,3 @@ class Session( object ):
|
||||
@property
|
||||
def callbackurl(self):
|
||||
return "http://www.themoviedb.org/authenticate/"+self._authtoken
|
||||
|
||||
Reference in new issue
Block a user