3 from eveapi import eveapi
7 # we will store our preferences in gconf
10 #ugly hack to check maemo version. any better way?
11 if hasattr(hildon, "StackableWindow"):
12 from ui.fremantle import ui
14 from ui.diablo import ui
18 self.program = hildon.Program()
19 self.program.__init__()
20 self.gconf = gnome.gconf.client_get_default()
22 self.ui = ui.mEveMonUI(self)
27 def quit(self, *args):
30 def get_api_key(self):
31 return self.gconf.get_string("/apps/maemo/mevemon/eve_api_key") or ''
34 return self.gconf.get_string("/apps/maemo/mevemon/eve_uid") or ''
36 def set_api_key(self, key):
37 self.gconf.set_string("/apps/maemo/mevemon/eve_api_key", key)
39 def set_uid(self, uid):
40 self.gconf.set_string("/apps/maemo/mevemon/eve_uid", uid)
45 api_key = self.get_api_key()
46 self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \
47 apicache.cache_handler( debug = False ) )
50 self.auth = self.cached_api.auth( userID = uid, apiKey = api_key )
51 except eveapi.Error, e:
52 # if we can't, return the error message/pic --danny
55 # unknown exception, dunno if this needs to be here if I just
56 # ignore it... probably a bad idea, but it was in the
57 # apitest.py example... --danny
63 def get_char_sheet(self, charID):
65 sheet = self.auth.character(charID).CharacterSheet()
66 except eveapi.Error, e:
67 # we should really have a logger that logs this error somewhere
72 def char_id2name(self, charID):
73 # the api can take a comma-seperated list of ids, but we'll just take
76 chars = self.cached_api.eve.CharacterName(ids=charID).characters
77 name = chars[0].characterName
78 except eveapi.Error, e:
83 def char_name2id(self, name):
84 # the api can take a comma-seperated list of names, but we'll just take
85 # a single name for now
87 chars = self.cached_api.eve.CharacterID(names=name).characters
88 char_id = chars[0].characterID
89 except eveapi.Error, e:
94 def get_account_balance(self, charID):
96 wallet = auth.char.AccountBalance(charID)
97 isk = wallet.accounts[0].balance # do we always want the first one??
98 except eveapi.Error, e:
103 # really quick hack to get character list. doesn't handle errors well, and
104 # if it can't get the gconf settings it just returns the placeholders, when
105 # in reality it should tell the UI or something. basically half finished,
106 # just uploading to show ry... FIXME --danny
107 def get_characters( self ):
109 # error message --danny
110 placeholder_chars = [("Please check your API settings.", "imgs/error.jpg")]
113 api_char_list = self.auth.account.Characters()
114 # append each char we get to the list we'll return to the UI --danny
115 for character in api_char_list.characters:
116 ui_char_list.append( ( character.name,
117 fetchimg.portrait_filename( character.characterID, 64 ) ) )
118 # if not entered into gconf, error message --danny
119 except eveapi.Error, e:
120 return placeholder_chars
124 def get_portrait(self, char_name, size):
126 returns the relative path of the retrieved portrait
128 charID = self.char_name2id(char_name)
129 return fetchimg.portrait_filename(charID, size)
131 if __name__ == "__main__":