-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.py
111 lines (67 loc) · 2.54 KB
/
key.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
Kristoffer Langeland Knudsen
"""
import urllib
import httplib
import xml.etree.ElementTree as ElementTree
def fromXML(elm):
print("Preparing key: " + elm.get('note'))
keyID = elm.findtext('keyID')
vCode = elm.findtext('vCode')
## Request key type from the EVE API servers.
info = {"keyID" : keyID, "vCode" : vCode}
conn = httplib.HTTPSConnection("api.eveonline.com")
conn.request("GET", "/account/APIKeyInfo.xml.aspx?" + urllib.urlencode(info))
response = conn.getresponse()
apiinfo = ElementTree.parse(response)
key = apiinfo.find(".//key")
t = key.get('type')
print(" Type: \t\t" + t)
handlers = {'Character' : Character,
'Account' : Character,
'Corporation' : Corporation}
return handlers[t](keyID, vCode, elm, key)
class Character:
"""
"""
def __init__(self, keyID, vCode, elm, key):
self.note = elm.get('note')
self.keyID = keyID
self.vCode = vCode
charIDs = [e.get('characterID') for e in key.iter('row')]
charNames = [e.get('characterName') for e in key.iter('row')]
requestedName = elm.findtext('character')
if len(charIDs) == 1:
print(" Found character: \t" + charNames[0])
self.charID = charIDs[0]
elif not requestedName:
print(" WARNING: Multiple characters found - defaulting to '" + charNames[0] + "'")
self.charID = charIDs[0]
else:
try:
# Look for the requested name.
self.charID = charIDs[charNames.index(requestedName)]
except e:
# Default to the first charID.
print(" WARNING: No character matched name '" + requestedName + "'")
print(" Defaulting to character '" + charNames[0] + "'")
self.charID = charIDs[0]
def getInfo(self):
return {'keyID' : self.keyID,
'vCode' : self.vCode,
'characterID' : self.charID}
def getPrefix(self):
return 'char'
class Corporation:
"""
"""
def __init__(self, keyID, vCode, elm, key):
self.note = elm.get('note')
self.keyID = keyID
self.vCode = vCode
def getInfo(self):
return {'keyID' : self.keyID,
'vCode' : self.vCode}
def getPrefix(self):
return 'corp'