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 set self.auth to None if there was a problem. somehow later on we'll
46 have to pass the error to the UI, but for now I just want the program
47 to not be broken. --danny
50 api_key = self.get_api_key()
51 self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \
52 apicache.cache_handler( debug = False ) )
54 self.auth = self.cached_api.auth( userID = uid, apiKey = api_key )
55 except eveapi.Error, e:
56 # we need to deal with this, so raise --danny
65 def get_char_sheet(self, charID):
66 if not self.auth: return None
68 sheet = self.auth.character(charID).CharacterSheet()
69 except eveapi.Error, e:
70 # we should really have a logger that logs this error somewhere
75 def char_id2name(self, charID):
76 # the api can take a comma-seperated list of ids, but we'll just take
79 chars = self.cached_api.eve.CharacterName(ids=charID).characters
80 name = chars[0].characterName
81 except eveapi.Error, e:
86 def char_name2id(self, name):
87 # the api can take a comma-seperated list of names, but we'll just take
88 # a single name for now
90 chars = self.cached_api.eve.CharacterID(names=name).characters
91 char_id = chars[0].characterID
92 except eveapi.Error, e:
97 def get_account_balance(self, charID):
98 if not self.auth: return None
100 wallet = self.auth.char.AccountBalance(CharacterID=charID)
101 isk = wallet.accounts[0].balance # do we always want the first one??
102 except eveapi.Error, e:
108 def get_characters( self ):
110 returns a list containing a single character with an error message for a
111 name, if there's a problem. FIXME --danny
114 placeholder_chars = [("Please check your API settings.", "imgs/error.jpg")]
115 if not self.auth: return placeholder_chars
117 api_char_list = self.auth.account.Characters()
118 # append each char we get to the list we'll return to the
120 for character in api_char_list.characters:
121 ui_char_list.append( ( character.name, fetchimg.portrait_filename( character.characterID, 64 ) ) )
122 except eveapi.Error, e:
123 # again, we need to handle this... --danny
128 def get_portrait(self, char_name, size):
130 returns the relative path of the retrieved portrait
132 charID = self.char_name2id(char_name)
133 return fetchimg.portrait_filename(charID, size)
135 if __name__ == "__main__":