mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-13 22:32:15 +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):
|
||||
|
||||
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 = []
|
||||
for obj in objs:
|
||||
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': ''}]}
|
||||
try:
|
||||
cached_doc = CachedDocument.objects.api_query('/char/UpcomingCalendarEvents.xml.aspx', params, timeout=10, service="Optimer")
|
||||
except DocumentRetrievalError:
|
||||
return error_doc
|
||||
dom = minidom.parseString(cached_doc.body.encode('utf-8'))
|
||||
if dom.getElementsByTagName('error'):
|
||||
error_doc['raw_xml'] = cached_doc.body
|
||||
return error_doc
|
||||
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': ''}]}
|
||||
try:
|
||||
cached_doc = CachedDocument.objects.api_query('/char/UpcomingCalendarEvents.xml.aspx', params, timeout=10, service="Optimer")
|
||||
except DocumentRetrievalError:
|
||||
return error_doc
|
||||
dom = minidom.parseString(cached_doc.body.encode('utf-8'))
|
||||
if dom.getElementsByTagName('error'):
|
||||
error_doc['raw_xml'] = cached_doc.body
|
||||
return error_doc
|
||||
|
||||
for node in dom.getElementsByTagName('rowset')[0].childNodes:
|
||||
if node.nodeType == 1:
|
||||
ownerID = node.getAttribute('ownerID')
|
||||
if ownerID != '1':
|
||||
dt = datetime.strptime(node.getAttribute('eventDate'), '%Y-%m-%d %H:%M:%S').replace(tzinfo=utc)
|
||||
startsIn = int(dt.strftime('%s')) - int(now().strftime('%s'))
|
||||
duration = int(node.getAttribute('duration'))
|
||||
for node in dom.getElementsByTagName('rowset')[0].childNodes:
|
||||
if node.nodeType == 1:
|
||||
ownerID = node.getAttribute('ownerID')
|
||||
if ownerID != '1':
|
||||
dt = datetime.strptime(node.getAttribute('eventDate'), '%Y-%m-%d %H:%M:%S').replace(tzinfo=utc)
|
||||
startsIn = int(dt.strftime('%s')) - int(now().strftime('%s'))
|
||||
duration = int(node.getAttribute('duration'))
|
||||
|
||||
fid = re.search('topic=[\d]+', node.getAttribute('eventText'))
|
||||
if fid:
|
||||
forumlink = 'http://forum.pleaseignore.com/index.php?%s' % fid.group(0)
|
||||
else:
|
||||
forumlink = ''
|
||||
#In case people forget to set a duration, we'll give a default of 1 hour
|
||||
if duration == 0:
|
||||
duration = 60
|
||||
endsIn = startsIn + (duration * 60)
|
||||
if startsIn < 0:
|
||||
startsIn = 0
|
||||
if endsIn > 0:
|
||||
event = {
|
||||
'startsIn': startsIn,
|
||||
'eventID': int(node.getAttribute('eventID')),
|
||||
'ownerName': node.getAttribute('ownerName'),
|
||||
'eventDate': date,
|
||||
'eventTitle': node.getAttribute('eventTitle'),
|
||||
'duration': duration,
|
||||
'isImportant': int(node.getAttribute('importance')),
|
||||
'eventText': node.getAttribute('eventText'),
|
||||
'endsIn':endsIn,
|
||||
'forumLink': forumlink}
|
||||
events.append(event)
|
||||
fid = re.search('topic=[\d]+', node.getAttribute('eventText'))
|
||||
if fid:
|
||||
forumlink = 'http://forum.pleaseignore.com/index.php?%s' % fid.group(0)
|
||||
else:
|
||||
forumlink = ''
|
||||
#In case people forget to set a duration, we'll give a default of 1 hour
|
||||
if duration == 0:
|
||||
duration = 60
|
||||
endsIn = startsIn + (duration * 60)
|
||||
if startsIn < 0:
|
||||
startsIn = 0
|
||||
if endsIn > 0:
|
||||
event = {
|
||||
'startsIn': startsIn,
|
||||
'eventID': int(node.getAttribute('eventID')),
|
||||
'ownerName': node.getAttribute('ownerName'),
|
||||
'eventDate': date,
|
||||
'eventTitle': node.getAttribute('eventTitle'),
|
||||
'duration': duration,
|
||||
'isImportant': int(node.getAttribute('importance')),
|
||||
'eventText': node.getAttribute('eventText'),
|
||||
'endsIn':endsIn,
|
||||
'forumLink': forumlink}
|
||||
events.append(event)
|
||||
|
||||
if len(events) == 0:
|
||||
return {'ops':[{
|
||||
|
||||
Reference in New Issue
Block a user