Op Timer API

This commit is contained in:
Aaron Static
2010-06-30 23:45:09 +10:00
parent a7c4ddcfdc
commit 1427caaa76
3 changed files with 51 additions and 0 deletions

46
api/handlers.py Normal file → Executable file
View File

@@ -16,6 +16,11 @@ from eve_proxy.models import CachedDocument
from eve_api.models import EVEAccount
from sso.models import ServiceAccount, Service
from settings import FULL_API_USER_ID
from settings import FULL_API_CHARACTER_ID
from xml.dom import minidom
class UserHandler(BaseHandler):
allowed_methods = ('GET')
@@ -111,3 +116,44 @@ class EveAPIProxyHandler(BaseHandler):
return HttpResponse(cached_doc.body)
class OpTimerHandler(BaseHandler):
allowed_methods = ('GET')
def read(self, request, id=None):
obj = get_object_or_404(EVEAccount, user=FULL_API_USER_ID)
params = {'userID':obj.id,'apiKey':obj.api_key,'characterID':FULL_API_CHARACTER_ID}
cached_doc = CachedDocument.objects.api_query('/char/UpcomingCalendarEvents.xml.aspx', params, exceptions=False)
dom = minidom.parseString(cached_doc.body.encode('utf-8'))
enode = dom.getElementsByTagName('error')
if enode:
return {'error':True}
events = []
events_node_children = dom.getElementsByTagName('rowset')[0].childNodes
for node in events_node_children:
if node.nodeType == 1:
ownerID = node.getAttribute('ownerID')
print ownerID
if ownerID != '1':
date = node.getAttribute('eventDate')
dt = datetime.strptime(date,'%Y-%m-%d %H:%M:%S')
now = datetime.utcnow()
startsIn = int(dt.strftime('%s')) - int(now.strftime('%s'))
event = {
'startsIn': startsIn,
'eventID': node.getAttribute('eventID'),
'ownerName': node.getAttribute('ownerName'),
'eventDate': date,
'eventTitle': node.getAttribute('eventTitle'),
'duration': node.getAttribute('duration'),
'isImportant': node.getAttribute('importance'),
'eventText': node.getAttribute('eventText')
}
events.append(event)
return {'ops':events}

2
api/urls.py Normal file → Executable file
View File

@@ -13,12 +13,14 @@ user_resource = Resource(handler=UserHandler, **oauth)
login_resource = Resource(handler=LoginHandler, **noauth)
eveapi_resource = Resource(handler=EveAPIHandler, **apikeyauth)
eveapiproxy_resource = Resource(handler=EveAPIProxyHandler, **apikeyauth)
optimer_resource = Resource(handler=OpTimerHandler, **apikeyauth)
urlpatterns = patterns('',
url(r'^user/$', user_resource),
url(r'^login/$', login_resource),
url(r'^eveapi/$', eveapi_resource),
url(r'^eveapi/', eveapiproxy_resource, name='api-eveapiproxy'),
url(r'^optimer/$', optimer_resource),
)
urlpatterns += patterns('piston.authentication',

3
settings.py Normal file → Executable file
View File

@@ -123,6 +123,9 @@ REDDIT_PASSWD = ''
HR_STAFF_GROUP = 'HR Staff'
FULL_API_USER_ID = 1
FULL_API_CHARACTER_ID = 217608501
# try and import local settings
try:
from settingslocal import *