mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Return a empty list if the API key isn't available for the optimer
This commit is contained in:
@@ -36,53 +36,65 @@ class OAuthOpTimerHandler(BaseHandler):
|
|||||||
|
|
||||||
def read(self, request, id=None):
|
def read(self, request, id=None):
|
||||||
|
|
||||||
objs = [get_object_or_404(EVEAccount, pk=settings.FULL_API_USER_ID)]
|
try:
|
||||||
|
obj = EVEAccount.object.get(pk=settings.FULL_API_USER_ID)
|
||||||
|
except EVEAccount.DoesNotExist:
|
||||||
|
return {'ops':[{
|
||||||
|
'startsIn': -1,
|
||||||
|
'eventID': 0,
|
||||||
|
'ownerName': '',
|
||||||
|
'eventDate': '',
|
||||||
|
'eventTitle': '<div style="text-align:center">The Optimer API is currently unavailable.</div>',
|
||||||
|
'duration': 0,
|
||||||
|
'isImportant': 0,
|
||||||
|
'eventText': '',
|
||||||
|
'endsIn':-1,
|
||||||
|
'forumLink': ''}]}
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
for obj in objs:
|
params = {'keyID': obj.pk, 'vCode': obj.api_key, 'characterID': settings.FULL_API_CHARACTER_ID}
|
||||||
params = {'keyID': obj.pk, 'vCode': obj.api_key, 'characterID': settings.FULL_API_CHARACTER_ID}
|
error_doc = {'ops': [{'startsIn': -1, 'eventID': 0, 'ownerName': '', 'eventDate': '', 'eventTitle': '<div style="text-align:center">The EVE API calendar is unavailable</div>', 'duration': 0, 'isImportant': 0, 'eventText': 'Fuck CCP tbqh imho srsly', 'endsIn':-1, 'forumLink': ''}]}
|
||||||
error_doc = {'ops': [{'startsIn': -1, 'eventID': 0, 'ownerName': '', 'eventDate': '', 'eventTitle': '<div style="text-align:center">The EVE API calendar is unavailable</div>', 'duration': 0, 'isImportant': 0, 'eventText': 'Fuck CCP tbqh imho srsly', 'endsIn':-1, 'forumLink': ''}]}
|
try:
|
||||||
try:
|
cached_doc = CachedDocument.objects.api_query('/char/UpcomingCalendarEvents.xml.aspx', params, timeout=10, service="Optimer")
|
||||||
cached_doc = CachedDocument.objects.api_query('/char/UpcomingCalendarEvents.xml.aspx', params, timeout=10, service="Optimer")
|
except DocumentRetrievalError:
|
||||||
except DocumentRetrievalError:
|
return error_doc
|
||||||
return error_doc
|
dom = minidom.parseString(cached_doc.body.encode('utf-8'))
|
||||||
dom = minidom.parseString(cached_doc.body.encode('utf-8'))
|
if dom.getElementsByTagName('error'):
|
||||||
if dom.getElementsByTagName('error'):
|
error_doc['raw_xml'] = cached_doc.body
|
||||||
error_doc['raw_xml'] = cached_doc.body
|
return error_doc
|
||||||
return error_doc
|
|
||||||
|
|
||||||
for node in dom.getElementsByTagName('rowset')[0].childNodes:
|
for node in dom.getElementsByTagName('rowset')[0].childNodes:
|
||||||
if node.nodeType == 1:
|
if node.nodeType == 1:
|
||||||
ownerID = node.getAttribute('ownerID')
|
ownerID = node.getAttribute('ownerID')
|
||||||
if ownerID != '1':
|
if ownerID != '1':
|
||||||
dt = datetime.strptime(node.getAttribute('eventDate'), '%Y-%m-%d %H:%M:%S').replace(tzinfo=utc)
|
dt = datetime.strptime(node.getAttribute('eventDate'), '%Y-%m-%d %H:%M:%S').replace(tzinfo=utc)
|
||||||
startsIn = int(dt.strftime('%s')) - int(now().strftime('%s'))
|
startsIn = int(dt.strftime('%s')) - int(now().strftime('%s'))
|
||||||
duration = int(node.getAttribute('duration'))
|
duration = int(node.getAttribute('duration'))
|
||||||
|
|
||||||
fid = re.search('topic=[\d]+', node.getAttribute('eventText'))
|
fid = re.search('topic=[\d]+', node.getAttribute('eventText'))
|
||||||
if fid:
|
if fid:
|
||||||
forumlink = 'http://forum.pleaseignore.com/index.php?%s' % fid.group(0)
|
forumlink = 'http://forum.pleaseignore.com/index.php?%s' % fid.group(0)
|
||||||
else:
|
else:
|
||||||
forumlink = ''
|
forumlink = ''
|
||||||
#In case people forget to set a duration, we'll give a default of 1 hour
|
#In case people forget to set a duration, we'll give a default of 1 hour
|
||||||
if duration == 0:
|
if duration == 0:
|
||||||
duration = 60
|
duration = 60
|
||||||
endsIn = startsIn + (duration * 60)
|
endsIn = startsIn + (duration * 60)
|
||||||
if startsIn < 0:
|
if startsIn < 0:
|
||||||
startsIn = 0
|
startsIn = 0
|
||||||
if endsIn > 0:
|
if endsIn > 0:
|
||||||
event = {
|
event = {
|
||||||
'startsIn': startsIn,
|
'startsIn': startsIn,
|
||||||
'eventID': int(node.getAttribute('eventID')),
|
'eventID': int(node.getAttribute('eventID')),
|
||||||
'ownerName': node.getAttribute('ownerName'),
|
'ownerName': node.getAttribute('ownerName'),
|
||||||
'eventDate': date,
|
'eventDate': date,
|
||||||
'eventTitle': node.getAttribute('eventTitle'),
|
'eventTitle': node.getAttribute('eventTitle'),
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'isImportant': int(node.getAttribute('importance')),
|
'isImportant': int(node.getAttribute('importance')),
|
||||||
'eventText': node.getAttribute('eventText'),
|
'eventText': node.getAttribute('eventText'),
|
||||||
'endsIn':endsIn,
|
'endsIn':endsIn,
|
||||||
'forumLink': forumlink}
|
'forumLink': forumlink}
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
if len(events) == 0:
|
if len(events) == 0:
|
||||||
return {'ops':[{
|
return {'ops':[{
|
||||||
|
|||||||
Reference in New Issue
Block a user