-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheveapi_simple.py
35 lines (27 loc) · 1.05 KB
/
eveapi_simple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""eveapi_simple.py: simple eve api query helper"""
from httplib import HTTPSConnection
from lxml import objectify
class APIError(Exception):
pass
def query(query, args=None):
"""Query the eve online API and return a result object."""
query = _make_query_string(query, args)
con = HTTPSConnection('api.eveonline.com')
con.request('GET', query)
response = con.getresponse()
if response.status != 200:
raise APIError("HTTPS GET failed")
return objectify.fromstring(response.read())
def _make_query_string(query, args=None):
if args is None:
args = {}
if not query.startswith('/'):
query = '/' + query
if not query.endswith(".xml.aspx"):
query += '.xml.aspx'
query_str = '?'.join(
[query, '&'.join(['='.join(map(str, i)) for i in args.items()])])
return query_str.replace(' ', '%20')