mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Op Timer API
This commit is contained in:
46
api/handlers.py
Normal file → Executable file
46
api/handlers.py
Normal file → Executable file
@@ -16,6 +16,11 @@ from eve_proxy.models import CachedDocument
|
|||||||
from eve_api.models import EVEAccount
|
from eve_api.models import EVEAccount
|
||||||
from sso.models import ServiceAccount, Service
|
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):
|
class UserHandler(BaseHandler):
|
||||||
allowed_methods = ('GET')
|
allowed_methods = ('GET')
|
||||||
@@ -110,4 +115,45 @@ class EveAPIProxyHandler(BaseHandler):
|
|||||||
cached_doc = CachedDocument.objects.api_query(url_path, params, exceptions=False)
|
cached_doc = CachedDocument.objects.api_query(url_path, params, exceptions=False)
|
||||||
|
|
||||||
return HttpResponse(cached_doc.body)
|
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
2
api/urls.py
Normal file → Executable file
@@ -13,12 +13,14 @@ user_resource = Resource(handler=UserHandler, **oauth)
|
|||||||
login_resource = Resource(handler=LoginHandler, **noauth)
|
login_resource = Resource(handler=LoginHandler, **noauth)
|
||||||
eveapi_resource = Resource(handler=EveAPIHandler, **apikeyauth)
|
eveapi_resource = Resource(handler=EveAPIHandler, **apikeyauth)
|
||||||
eveapiproxy_resource = Resource(handler=EveAPIProxyHandler, **apikeyauth)
|
eveapiproxy_resource = Resource(handler=EveAPIProxyHandler, **apikeyauth)
|
||||||
|
optimer_resource = Resource(handler=OpTimerHandler, **apikeyauth)
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^user/$', user_resource),
|
url(r'^user/$', user_resource),
|
||||||
url(r'^login/$', login_resource),
|
url(r'^login/$', login_resource),
|
||||||
url(r'^eveapi/$', eveapi_resource),
|
url(r'^eveapi/$', eveapi_resource),
|
||||||
url(r'^eveapi/', eveapiproxy_resource, name='api-eveapiproxy'),
|
url(r'^eveapi/', eveapiproxy_resource, name='api-eveapiproxy'),
|
||||||
|
url(r'^optimer/$', optimer_resource),
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns += patterns('piston.authentication',
|
urlpatterns += patterns('piston.authentication',
|
||||||
|
|||||||
3
settings.py
Normal file → Executable file
3
settings.py
Normal file → Executable file
@@ -123,6 +123,9 @@ REDDIT_PASSWD = ''
|
|||||||
|
|
||||||
HR_STAFF_GROUP = 'HR Staff'
|
HR_STAFF_GROUP = 'HR Staff'
|
||||||
|
|
||||||
|
FULL_API_USER_ID = 1
|
||||||
|
FULL_API_CHARACTER_ID = 217608501
|
||||||
|
|
||||||
# try and import local settings
|
# try and import local settings
|
||||||
try:
|
try:
|
||||||
from settingslocal import *
|
from settingslocal import *
|
||||||
|
|||||||
Reference in New Issue
Block a user