def skills(self, api_result=None): """Returns a specific character's skills.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'free_skillpoints': _int('freeSkillPoints'), } rowsets = {} for rowset in api_result.result.findall('rowset'): key = rowset.attrib['name'] rowsets[key] = rowset result['skills'] = {} result['skillpoints'] = 0 for skill in rowsets['skills']: a = skill.attrib skill_id = int(a['typeID']) sp = int(a['skillpoints']) result['skills'][skill_id] = { 'id': skill_id, 'skillpoints': sp, 'level': int(a['level']), 'published': a['published'] == '1', } result['skillpoints'] += sp return api.APIResult(result, api_result.timestamp, api_result.expires)
def faction_warfare_stats(self, api_result=None): """Returns FW stats for this character, if enrolled in FW. NOTE: This will return an error instead if the character is not enrolled in Faction Warfare. """ _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'faction': { 'id': _int('factionID'), 'name': _str('factionName'), }, 'enlist_ts': _ts('enlisted'), 'rank': { 'current': _int('currentRank'), 'highest': _int('highestRank'), }, 'kills': { 'yesterday': _int('killsYesterday'), 'week': _int('killsLastWeek'), 'total': _int('killsTotal'), }, 'points': { 'yesterday': _int('victoryPointsYesterday'), 'week': _int('victoryPointsLastWeek'), 'total': _int('victoryPointsTotal'), }, } return api.APIResult(result, api_result.timestamp, api_result.expires)
def faction_warfare_stats(self): """Returns FW stats for this character, if enrolled in FW. NOTE: This will return an error instead if the character is not enrolled in Faction Warfare. """ api_result = self.api.get('char/FacWarStats', {'characterID': self.char_id}) _str, _int, _float, _bool, _ts = api.elem_getters(api_result) return { 'faction': { 'id': _int('factionID'), 'name': _str('factionName'), }, 'enlist_ts': _ts('enlisted'), 'rank': { 'current': _int('currentRank'), 'highest': _int('highestRank'), }, 'kills': { 'yesterday': _int('killsYesterday'), 'week': _int('killsLastWeek'), 'total': _int('killsTotal'), }, 'points': { 'yesterday': _int('victoryPointsYesterday'), 'week': _int('victoryPointsLastWeek'), 'total': _int('victoryPointsTotal'), }, }
def faction_warfare_stats(self, api_result=None): """Return various statistics from Faction Warfare.""" if api_result is None: api_result = self.api.get('eve/FacWarStats') totals = api_result.result.find('totals') rowsets = dict((r.attrib['name'], r) for r in api_result.result.findall('rowset')) _str, _int, _float, _bool, _ts = api.elem_getters(totals) results = { 'kills': { 'yesterday': _int('killsYesterday'), 'week': _int('killsLastWeek'), 'total': _int('killsTotal'), }, 'points': { 'yesterday': _int('victoryPointsYesterday'), 'week': _int('victoryPointsLastWeek'), 'total': _int('victoryPointsTotal'), }, 'factions': {}, 'wars': [], } for row in rowsets['factions'].findall('row'): a = row.attrib faction = { 'id': int(a['factionID']), 'name': a['factionName'], 'pilots': int(a['pilots']), 'systems': int(a['systemsControlled']), 'kills': { 'yesterday': int(a['killsYesterday']), 'week': int(a['killsLastWeek']), 'total': int(a['killsTotal']), }, 'points': { 'yesterday': int(a['victoryPointsYesterday']), 'week': int(a['victoryPointsLastWeek']), 'total': int(a['victoryPointsTotal']), }, } results['factions'][faction['id']] = faction for row in rowsets['factionWars'].findall('row'): a = row.attrib war = { 'faction': { 'id': int(a['factionID']), 'name': a['factionName'], }, 'against': { 'id': int(a['againstID']), 'name': a['againstName'], }, } results['wars'].append(war) return api.APIResult(results, api_result.timestamp, api_result.expires)
def faction_warfare_stats(self): """Returns stats from faction warfare if this corp is enrolled. NOTE: This will raise an APIError if the corp is not enrolled in Faction Warfare. """ api_result = self.api.get('corp/FacWarStats') _str, _int, _float, _bool, _ts = api.elem_getters(api_result) return { 'faction': { 'id': _int('factionID'), 'name': _str('factionName'), }, 'start_ts': _ts('enlisted'), 'pilots': _int('pilots'), 'kills': { 'yesterday': _int('killsYesterday'), 'week': _int('killsLastWeek'), 'total': _int('killsTotal'), }, 'points': { 'yesterday': _int('victoryPointsYesterday'), 'week': _int('victoryPointsLastWeek'), 'total': _int('victoryPointsTotal'), }, }
def character_info_from_id(self, char_id, api_result=None): """Retrieve a dict of info about the designated character.""" if api_result is None: raise ValueError("Unable to fetch info for character %r" % char_id) _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) results = { "id": _int("characterID"), "name": _str("characterName"), "race": _str("race"), "bloodline": _str("bloodline"), "sec_status": _float("securityStatus"), "skillpoints": _int("skillPoints"), "location": _str("lastKnownLocation"), "isk": _float("accountBalance"), "corp": {"id": _int("corporationID"), "name": _str("corporation"), "timestamp": _ts("corporationDate")}, "alliance": {"id": _int("allianceID"), "name": _str("alliance"), "timestamp": _ts("allianceDate")}, "ship": {"name": _str("shipName"), "type_id": _int("shipTypeID"), "type_name": _str("shipTypeName")}, "history": [], } # Add in corp history history = api_result.result.find("rowset") for row in history.findall("row"): corp_id = int(row.attrib["corporationID"]) start_date = api.parse_ts(row.attrib["startDate"]) results["history"].append({"corp_id": corp_id, "start_ts": start_date}) return api.APIResult(results, api_result.timestamp, api_result.expires)
def faction_warfare_stats(self, api_result=None): """Returns stats from faction warfare if this corp is enrolled. NOTE: This will raise an APIError if the corp is not enrolled in Faction Warfare. """ _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'faction': { 'id': _int('factionID'), 'name': _str('factionName'), }, 'start_ts': _ts('enlisted'), 'pilots': _int('pilots'), 'kills': { 'yesterday': _int('killsYesterday'), 'week': _int('killsLastWeek'), 'total': _int('killsTotal'), }, 'points': { 'yesterday': _int('victoryPointsYesterday'), 'week': _int('victoryPointsLastWeek'), 'total': _int('victoryPointsTotal'), }, } return api.APIResult(result, api_result.timestamp, api_result.expires)
def clones(self, api_result=None): """Returns jumpclones for a specific character.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'create_ts': _ts('DoB'), 'race': _str('race'), 'bloodline': _str('bloodLine'), 'ancestry': _str('ancestry'), 'remote_station_ts': _ts('remoteStationDate'), 'last_respec_ts': _ts('lastRespecDate'), 'last_timed_respec_ts': _ts('lastTimedRespec'), 'free_respecs': _int('freeRespecs'), 'gender': _str('gender'), 'attributes': {}, 'implants': {}, 'jumpclone': { 'jump_ts': _ts('cloneJumpDate'), }, } for attr in ('intelligence', 'memory', 'charisma', 'perception', 'willpower'): result['attributes'][attr] = {} base = int(api_result.result.findtext('attributes/%s' % attr)) result['attributes'][attr]['base'] = base rowsets = {} for rowset in api_result.result.findall('rowset'): key = rowset.attrib['name'] rowsets[key] = rowset for implant in rowsets['implants']: a = implant.attrib result['implants'][int(a['typeID'])] = a['typeName'] jumpclone_implants = {} for implant in rowsets['jumpCloneImplants']: a = implant.attrib jumpclone_id = int(a['jumpCloneID']) implants = jumpclone_implants.setdefault(jumpclone_id, {}) implants[int(a['typeID'])] = a['typeName'] result['jumpclone']['clones'] = {} for jumpclone in rowsets['jumpClones']: a = jumpclone.attrib jumpclone_id = int(a['jumpCloneID']) location_id = int(a['locationID']) # This is keyed off location_id because it simplifies a # common lookup ("what systems do I have jumpclones in") result['jumpclone']['clones'][location_id] = { 'id': jumpclone_id, 'name': a['cloneName'], 'type_id': int(a['typeID']), 'location_id': location_id, 'implants': jumpclone_implants.get(jumpclone_id, {}) } return api.APIResult(result, api_result.timestamp, api_result.expires)
def faction_warfare_stats(self, api_result=None): """Return various statistics from Faction Warfare.""" totals = api_result.result.find('totals') rowsets = dict( (r.attrib['name'], r) for r in api_result.result.findall('rowset')) _str, _int, _float, _bool, _ts = api.elem_getters(totals) results = { 'kills': { 'yesterday': _int('killsYesterday'), 'week': _int('killsLastWeek'), 'total': _int('killsTotal'), }, 'points': { 'yesterday': _int('victoryPointsYesterday'), 'week': _int('victoryPointsLastWeek'), 'total': _int('victoryPointsTotal'), }, 'factions': {}, 'wars': [], } for row in rowsets['factions'].findall('row'): a = row.attrib faction = { 'id': int(a['factionID']), 'name': a['factionName'], 'pilots': int(a['pilots']), 'systems': int(a['systemsControlled']), 'kills': { 'yesterday': int(a['killsYesterday']), 'week': int(a['killsLastWeek']), 'total': int(a['killsTotal']), }, 'points': { 'yesterday': int(a['victoryPointsYesterday']), 'week': int(a['victoryPointsLastWeek']), 'total': int(a['victoryPointsTotal']), }, } results['factions'][faction['id']] = faction for row in rowsets['factionWars'].findall('row'): a = row.attrib war = { 'faction': { 'id': int(a['factionID']), 'name': a['factionName'], }, 'against': { 'id': int(a['againstID']), 'name': a['againstName'], }, } results['wars'].append(war) return api.APIResult(results, api_result.timestamp, api_result.expires)
def get_logo_details(logo_result): _str, _int, _float, _bool, _ts = api.elem_getters(logo_result) return { 'graphic_id': _int('graphicID'), 'shapes': [ {'id': _int('shape1'), 'color': _int('color1')}, {'id': _int('shape2'), 'color': _int('color2')}, {'id': _int('shape3'), 'color': _int('color3')}, ], }
def character_info_from_id(self, char_id, api_result=None): """Retrieve a dict of info about the designated character.""" if api_result is None: api_result = self.api.get('eve/CharacterInfo', { 'characterID': char_id, }) if api_result is None: raise ValueError("Unable to fetch info for character %r" % char_id) _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) results = { 'id': _int('characterID'), 'name': _str('characterName'), 'race': _str('race'), 'bloodline': _str('bloodline'), 'sec_status': _float('securityStatus'), 'skillpoints': _int('skillPoints'), 'location': _str('lastKnownLocation'), 'isk': _float('accountBalance'), 'corp': { 'id': _int('corporationID'), 'name': _str('corporation'), 'timestamp': _ts('corporationDate'), }, 'alliance': { 'id': _int('allianceID'), 'name': _str('alliance'), 'timestamp': _ts('allianceDate'), }, 'ship': { 'name': _str('shipName'), 'type_id': _int('shipTypeID'), 'type_name': _str('shipTypeName'), }, 'history': [], } # Add in corp history history = api_result.result.find('rowset') for row in history.findall('row'): corp_id = int(row.attrib['corporationID']) start_date = api.parse_ts(row.attrib['startDate']) results['history'].append({ 'corp_id': corp_id, 'start_ts': start_date, }) return api.APIResult(results, api_result.timestamp, api_result.expires)
def status(self): """Returns the account's subscription status.""" api_result = self.api.get('account/AccountStatus') _str, _int, _float, _bool, _ts = api.elem_getters(api_result) return { 'paid_ts': _ts('paidUntil'), 'create_ts': _ts('createDate'), 'logins': _int('logonCount'), 'minutes_played': _int('logonMinutes'), }
def status(self, api_result=None): """Returns the account's subscription status.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'paid_ts': _ts('paidUntil'), 'create_ts': _ts('createDate'), 'logins': _int('logonCount'), 'minutes_played': _int('logonMinutes'), } return api.APIResult(result, api_result.timestamp, api_result.expires)
def current_training(self, api_result=None): """Returns the skill that is currently being trained by a specified character""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'start_ts': _ts('trainingStartTime'), 'end_ts': _ts('trainingEndTime'), 'type_id': _int('trainingTypeID'), 'start_sp': _int('trainingStartSP'), 'end_sp': _int('trainingDestinationSP'), 'current_ts': _ts('currentTQTime'), 'level': _int('trainingToLevel'), 'active': _bool('skillInTraining'), } return api.APIResult(result, api_result.timestamp, api_result.expires)
def current_training(self, api_result=None): """Returns the skill that is currently being trained by a specified character""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { "start_ts": _ts("trainingStartTime"), "end_ts": _ts("trainingEndTime"), "type_id": _int("trainingTypeID"), "start_sp": _int("trainingStartSP"), "end_sp": _int("trainingDestinationSP"), "current_ts": _ts("currentTQTime"), "level": _int("trainingToLevel"), "active": _bool("skillInTraining"), } return api.APIResult(result, api_result.timestamp, api_result.expires)
def character_info_from_id(self, char_id, api_result=None): """Retrieve a dict of info about the designated character.""" if api_result is None: raise ValueError("Unable to fetch info for character %r" % char_id) _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) results = { 'id': _int('characterID'), 'name': _str('characterName'), 'race': _str('race'), 'bloodline': _str('bloodline'), 'sec_status': _float('securityStatus'), 'skillpoints': _int('skillPoints'), 'location': _str('lastKnownLocation'), 'isk': _float('accountBalance'), 'corp': { 'id': _int('corporationID'), 'name': _str('corporation'), 'timestamp': _ts('corporationDate'), }, 'alliance': { 'id': _int('allianceID'), 'name': _str('alliance'), 'timestamp': _ts('allianceDate'), }, 'ship': { 'name': _str('shipName'), 'type_id': _int('shipTypeID'), 'type_name': _str('shipTypeName'), }, 'history': [], } # Add in corp history history = api_result.result.find('rowset') for row in history.findall('row'): corp_id = int(row.attrib['corporationID']) corp_name = row.attrib['corporationName'] start_date = api.parse_ts(row.attrib['startDate']) results['history'].append({ 'corp_id': corp_id, 'corp_name': corp_name, 'start_ts': start_date, }) return api.APIResult(results, api_result.timestamp, api_result.expires)
def faction_warfare_stats(self, api_result=None): """Return various statistics from Faction Warfare.""" totals = api_result.result.find("totals") rowsets = dict((r.attrib["name"], r) for r in api_result.result.findall("rowset")) _str, _int, _float, _bool, _ts = api.elem_getters(totals) results = { "kills": {"yesterday": _int("killsYesterday"), "week": _int("killsLastWeek"), "total": _int("killsTotal")}, "points": { "yesterday": _int("victoryPointsYesterday"), "week": _int("victoryPointsLastWeek"), "total": _int("victoryPointsTotal"), }, "factions": {}, "wars": [], } for row in rowsets["factions"].findall("row"): a = row.attrib faction = { "id": int(a["factionID"]), "name": a["factionName"], "pilots": int(a["pilots"]), "systems": int(a["systemsControlled"]), "kills": { "yesterday": int(a["killsYesterday"]), "week": int(a["killsLastWeek"]), "total": int(a["killsTotal"]), }, "points": { "yesterday": int(a["victoryPointsYesterday"]), "week": int(a["victoryPointsLastWeek"]), "total": int(a["victoryPointsTotal"]), }, } results["factions"][faction["id"]] = faction for row in rowsets["factionWars"].findall("row"): a = row.attrib war = { "faction": {"id": int(a["factionID"]), "name": a["factionName"]}, "against": {"id": int(a["againstID"]), "name": a["againstName"]}, } results["wars"].append(war) return api.APIResult(results, api_result.timestamp, api_result.expires)
def status(self, api_result=None): """Returns the account's subscription status.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { "paid_ts": _ts("paidUntil"), "create_ts": _ts("createDate"), "logins": _int("logonCount"), "minutes_played": _int("logonMinutes"), } rowsets = dict((r.attrib["name"], r) for r in api_result.result.findall("rowset")) result["multi_training_ends"] = [ api.parse_ts(m.attrib["trainingEnd"]) for m in rowsets["multiCharacterTraining"] ] return api.APIResult(result, api_result.timestamp, api_result.expires)
def current_training(self): """Returns the skill that is currently being trained by a specified character""" api_result = self.api.get('char/SkillInTraining', {'characterID': self.char_id}) _str, _int, _float, _bool, _ts = api.elem_getters(api_result) result = { 'start_ts': _ts('trainingStartTime'), 'end_ts': _ts('trainingEndTime'), 'type_id': _int('trainingTypeID'), 'start_sp': _int('trainingStartSP'), 'end_sp': _int('trainingDestinationSP'), 'current_ts': _ts('currentTQTime'), 'level': _int('trainingToLevel'), 'active': _bool('skillInTraining'), } return result
def status(self, api_result=None): """Returns the account's subscription status.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'paid_ts': _ts('paidUntil'), 'create_ts': _ts('createDate'), 'logins': _int('logonCount'), 'minutes_played': _int('logonMinutes'), } rowsets = dict( (r.attrib['name'], r) for r in api_result.result.findall('rowset')) result['multi_training_ends'] = [ api.parse_ts(m.attrib['trainingEnd']) for m in rowsets['multiCharacterTraining'] ] return api.APIResult(result, api_result.timestamp, api_result.expires)
def faction_warfare_stats(self, api_result=None): """Returns FW stats for this character, if enrolled in FW. NOTE: This will return an error instead if the character is not enrolled in Faction Warfare. """ _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { "faction": {"id": _int("factionID"), "name": _str("factionName")}, "enlist_ts": _ts("enlisted"), "rank": {"current": _int("currentRank"), "highest": _int("highestRank")}, "kills": {"yesterday": _int("killsYesterday"), "week": _int("killsLastWeek"), "total": _int("killsTotal")}, "points": { "yesterday": _int("victoryPointsYesterday"), "week": _int("victoryPointsLastWeek"), "total": _int("victoryPointsTotal"), }, } return api.APIResult(result, api_result.timestamp, api_result.expires)
def skill_tree(self, api_result=None): """Return a dict of all available skill groups.""" rowset = api_result.result.find('rowset') # skillGroups results = {} name_cache = {} for row in rowset.findall('row'): # the skill group data g = row.attrib group = { 'id': int(g['groupID']), 'name': g['groupName'], 'skills': {} } # Because :ccp: groups can sometimes be listed # multiple times with different skills, and the # correct result is to add the contents together group = results.get(group['id'], group) # now get the actual skill data skills_rs = row.find('rowset') # skills for skill_row in skills_rs.findall('row'): a = skill_row.attrib _str, _int, _float, _bool, _ts = api.elem_getters(skill_row) req_attrib = skill_row.find('requiredAttributes') skill = { 'id': int(a['typeID']), 'group_id': int(a['groupID']), 'name': a['typeName'], 'published': (a['published'] == '1'), 'description': _str('description'), 'rank': _int('rank'), 'required_skills': {}, 'bonuses': {}, 'attributes': { 'primary': api.get_named_value(req_attrib, 'primaryAttribute'), 'secondary': api.get_named_value(req_attrib, 'secondaryAttribute'), } } name_cache[skill['id']] = skill['name'] # Check each rowset inside the skill, and branch based on the name attribute for sub_rs in skill_row.findall('rowset'): if sub_rs.attrib['name'] == 'requiredSkills': for sub_row in sub_rs.findall('row'): b = sub_row.attrib req = { 'level': int(b['skillLevel']), 'id': int(b['typeID']), } skill['required_skills'][req['id']] = req elif sub_rs.attrib['name'] == 'skillBonusCollection': for sub_row in sub_rs.findall('row'): b = sub_row.attrib bonus = { 'type': b['bonusType'], 'value': float(b['bonusValue']), } skill['bonuses'][bonus['type']] = bonus group['skills'][skill['id']] = skill results[group['id']] = group # Second pass to fill in required skill names for group in results.values(): for skill in group['skills'].values(): for skill_id, skill_info in skill['required_skills'].items(): skill_info['name'] = name_cache.get(skill_id) return api.APIResult(results, api_result.timestamp, api_result.expires)
def character_sheet(self, api_result=None): """Returns attributes relating to a specific character.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'id': _int('characterID'), 'name': _str('name'), 'create_ts': _ts('DoB'), 'race': _str('race'), 'bloodline': _str('bloodLine'), 'ancestry': _str('ancestry'), 'gender': _str('gender'), 'corp': { 'id': _int('corporationID'), 'name': _str('corporationName'), }, 'alliance': { 'id': _int('allianceID') or None, 'name': _str('allianceName'), }, 'clone': { 'name': _str('cloneName'), 'skillpoints': _int('cloneSkillPoints'), }, 'balance': _float('balance'), 'attributes': {}, } for attr in ('intelligence', 'memory', 'charisma', 'perception', 'willpower'): result['attributes'][attr] = {} base = int(api_result.result.findtext('attributes/%s' % attr)) result['attributes'][attr]['base'] = base result['attributes'][attr]['total'] = base bonus = api_result.result.find('attributeEnhancers/%sBonus' % attr) if bonus is not None: mod = int(bonus.findtext('augmentatorValue')) result['attributes'][attr]['total'] += mod result['attributes'][attr]['bonus'] = { 'name': bonus.findtext('augmentatorName'), 'value': mod, } rowsets = {} for rowset in api_result.result.findall('rowset'): key = rowset.attrib['name'] rowsets[key] = rowset result['skills'] = [] result['skillpoints'] = 0 for skill in rowsets['skills']: a = skill.attrib sp = int(a['skillpoints']) result['skills'].append({ 'id': int(a['typeID']), 'skillpoints': sp, 'level': int(a['level']), 'published': a['published'] == '1', }) result['skillpoints'] += sp result['certificates'] = set() for cert in rowsets['certificates']: result['certificates'].add(int(cert.attrib['certificateID'])) result['roles'] = {} for our_role, ccp_role in constants.Char().corp_roles.items(): result['roles'][our_role] = {} for role in rowsets[ccp_role]: a = role.attrib role_id = int(a['roleID']) result['roles'][our_role][role_id] = { 'id': role_id, 'name': a['roleName'], } result['titles'] = {} for title in rowsets['corporationTitles']: a = title.attrib title_id = int(a['titleID']) result['titles'][title_id] = { 'id': title_id, 'name': a['titleName'], } return api.APIResult(result, api_result.timestamp, api_result.expires)
def corporation_sheet(self, corp_id=None): """Get information about a corporation. NOTE: This method may be called with or without specifying a corporation ID. If a corporation ID is specified, the public information for that corporation will be returned, and no api key is necessary. If a corporation ID is *not* specified, a corp api key *must* be provided, and the private information for that corporation will be returned along with the public info. """ params = {} if corp_id is not None: params['corporationID'] = corp_id api_result = self.api.get("corp/CorporationSheet", params) def get_logo_details(logo_result): _str, _int, _float, _bool, _ts = api.elem_getters(logo_result) return { 'graphic_id': _int('graphicID'), 'shapes': [ {'id': _int('shape1'), 'color': _int('color1')}, {'id': _int('shape2'), 'color': _int('color2')}, {'id': _int('shape3'), 'color': _int('color3')}, ], } _str, _int, _float, _bool, _ts = api.elem_getters(api_result) result = { 'id': _int('corporationID'), 'name': _str('corporationName'), 'ticker': _str('ticker'), 'ceo': { 'id': _int('ceoID'), 'name': _str('ceoName'), }, 'hq': { 'id': _int('stationID'), 'name': _str('stationName'), }, 'description': _str('description'), 'url': _str('url'), 'alliance': { 'id': _int('allianceID') or None, 'name': _str('allianceName') or None, }, 'tax_percent': _float('taxRate'), 'members': { 'current': _int('memberCount'), }, 'shares': _int('shares'), 'logo': get_logo_details(api_result.find('logo')), } if corp_id is None: result['members']['limit'] = _int('memberLimit') rowsets = dict((r.attrib['name'], r) for r in api_result.findall('rowset')) division_types = { 'hangars': 'divisions', 'wallets': 'walletDivisions', } for key, rowset_name in division_types.iteritems(): divisions = {} for row in rowsets[rowset_name].findall('row'): a = row.attrib divisions[int(a['accountKey'])] = a['description'] result[key] = divisions return result
def skill_tree(self, api_result=None): """Return a dict of all available skill groups.""" rowset = api_result.result.find('rowset') # skillGroups results = {} name_cache = {} for row in rowset.findall('row'): # the skill group data g = row.attrib group = { 'id': int(g['groupID']), 'name': g['groupName'], 'skills': {} } # Because :ccp: groups can sometimes be listed # multiple times with different skills, and the # correct result is to add the contents together group = results.get(group['id'], group) # now get the actual skill data skills_rs = row.find('rowset') # skills for skill_row in skills_rs.findall('row'): a = skill_row.attrib _str, _int, _float, _bool, _ts = api.elem_getters(skill_row) req_attrib = skill_row.find('requiredAttributes') skill = { 'id': int(a['typeID']), 'group_id': int(a['groupID']), 'name': a['typeName'], 'published': (a['published'] == '1'), 'description': _str('description'), 'rank': _int('rank'), 'required_skills': {}, 'bonuses': {}, 'attributes': { 'primary': api.get_named_value(req_attrib, 'primaryAttribute'), 'secondary': api.get_named_value(req_attrib, 'secondaryAttribute'), } } name_cache[skill['id']] = skill['name'] # Check each rowset inside the skill, and branch based on the name attribute for sub_rs in skill_row.findall('rowset'): if sub_rs.attrib['name'] == 'requiredSkills': for sub_row in sub_rs.findall('row'): b = sub_row.attrib req = { 'level': int(b['skillLevel']), 'id': int(b['typeID']), } skill['required_skills'][req['id']] = req elif sub_rs.attrib['name'] == 'skillBonusCollection': for sub_row in sub_rs.findall('row'): b = sub_row.attrib bonus = { 'type': b['bonusType'], 'value': float(b['bonusValue']), } skill['bonuses'][bonus['type']] = bonus group['skills'][skill['id']] = skill results[group['id']] = group # Second pass to fill in required skill names for group in results.itervalues(): for skill in group['skills'].itervalues(): for skill_id, skill_info in skill['required_skills'].iteritems(): skill_info['name'] = name_cache.get(skill_id) return api.APIResult(results, api_result.timestamp, api_result.expires)
def character_sheet(self): """Returns attributes relating to a specific character.""" api_result = self.api.get('char/CharacterSheet', {'characterID': self.char_id}) _str, _int, _float, _bool, _ts = api.elem_getters(api_result) result = { 'id': _int('characterID'), 'name': _str('name'), 'create_ts': _ts('DoB'), 'race': _str('race'), 'bloodline': _str('bloodLine'), 'ancestry': _str('ancestry'), 'gender': _str('gender'), 'corp': { 'id': _int('corporationID'), 'name': _str('corporationName'), }, 'alliance': { 'id': _int('allianceID') or None, 'name': _str('allianceName'), }, 'clone': { 'name': _str('cloneName'), 'skillpoints': _int('cloneSkillPoints'), }, 'balance': _float('balance'), 'attributes': {}, } for attr in ('intelligence', 'memory', 'charisma', 'perception', 'willpower'): result['attributes'][attr] = {} base = int(api_result.findtext('attributes/%s' % attr)) result['attributes'][attr]['base'] = base result['attributes'][attr]['total'] = base bonus = api_result.find('attributeEnhancers/%sBonus' % attr) if bonus is not None: mod = int(bonus.findtext('augmentatorValue')) result['attributes'][attr]['total'] += mod result['attributes'][attr]['bonus'] = { 'name': bonus.findtext('augmentatorName'), 'value': mod, } rowsets = {} for rowset in api_result.findall('rowset'): key = rowset.attrib['name'] rowsets[key] = rowset result['skills'] = [] result['skillpoints'] = 0 for skill in rowsets['skills']: a = skill.attrib sp = int(a['skillpoints']) result['skills'].append({ 'id': int(a['typeID']), 'skillpoints': sp, 'level': int(a['level']), 'published': a['published'] == '1', }) result['skillpoints'] += sp result['certificates'] = set() for cert in rowsets['certificates']: result['certificates'].add(int(cert.attrib['certificateID'])) result['roles'] = {} for our_role, ccp_role in constants.Char().corp_roles.iteritems(): result['roles'][our_role] = {} for role in rowsets[ccp_role]: a = role.attrib role_id = int(a['roleID']) result['roles'][our_role][role_id] = { 'id': role_id, 'name': a['roleName'], } result['titles'] = {} for title in rowsets['corporationTitles']: a = title.attrib title_id = int(a['titleID']) result['titles'][title_id] = { 'id': title_id, 'name': a['titleName'], } return result
def starbase_details(self, starbase_id): """Returns details about the specified POS.""" api_result = self.api.get('corp/StarbaseDetail', {'itemID': starbase_id}) _str, _int, _float, _bool, _ts = api.elem_getters(api_result) general_settings = api_result.find('generalSettings') combat_settings = api_result.find('combatSettings') def get_fuel_bay_perms(settings): # Two 2-bit fields usage_flags = int(settings.find('usageFlags').text) take_value = usage_flags % 4 view_value = (usage_flags >> 2) % 4 return { 'view': constants.Corp.pos_permission_entities[view_value], 'take': constants.Corp.pos_permission_entities[take_value], } def get_deploy_perms(settings): # Four 2-bit fields deploy_flags = int(settings.find('deployFlags').text) anchor_value = (deploy_flags >> 6) % 4 unanchor_value = (deploy_flags >> 4) % 4 online_value = (deploy_flags >> 2) % 4 offline_value = deploy_flags % 4 return { 'anchor': constants.Corp.pos_permission_entities[anchor_value], 'unanchor': constants.Corp.pos_permission_entities[unanchor_value], 'online': constants.Corp.pos_permission_entities[online_value], 'offline': constants.Corp.pos_permission_entities[offline_value], } def get_combat_settings(settings): result = { 'standings_owner_id': int(settings.find('useStandingsFrom').attrib['ownerID']), 'hostility': {}, } hostility = result['hostility'] # TODO(ayust): The fields returned by the API don't completely match up with # the fields available in-game. May want to revisit this in the future. standing = settings.find('onStandingDrop') hostility['standing'] = { 'threshold': float(standing.attrib['standing']) / 100, 'enabled': standing.attrib.get('enabled') != '0', } sec_status = settings.find('onStatusDrop') hostility['sec_status'] = { 'threshold': float(sec_status.attrib['standing']) / 100, 'enabled': sec_status.attrib.get('enabled') != '0', } hostility['aggression'] = { 'enabled': settings.find('onAggression').get('enabled') != '0', } hostility['war'] = { 'enabled': settings.find('onCorporationWar').get('enabled') != '0', } return result result = { 'state': constants.Corp.pos_states[_int('state')], 'state_ts': _ts('stateTimestamp'), 'online_ts': _ts('onlineTimestamp'), 'permissions': { 'fuel': get_fuel_bay_perms(general_settings), 'deploy': get_deploy_perms(general_settings), 'forcefield': { 'corp': general_settings.find('allowCorporationMembers').text == '1', 'alliance': general_settings.find('allowAllianceMembers').text == '1', }, }, 'combat': get_combat_settings(combat_settings), 'fuel': {}, } rowset = api_result.find('rowset') for row in rowset.findall('row'): a = row.attrib result['fuel'][int(a['typeID'])] = int(a['quantity']) return result
def character_sheet(self, api_result=None): """Returns attributes relating to a specific character.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'id': _int('characterID'), 'name': _str('name'), 'create_ts': _ts('DoB'), 'race': _str('race'), 'bloodline': _str('bloodLine'), 'ancestry': _str('ancestry'), 'gender': _str('gender'), 'corp': { 'id': _int('corporationID'), 'name': _str('corporationName'), }, 'alliance': { 'id': _int('allianceID') or None, 'name': _str('allianceName'), }, 'balance': _float('balance'), 'attributes': {}, 'implants': {}, 'jump': { 'activation_ts': _ts('jumpActivation'), 'fatigue_ts': _ts('jumpFatigue'), 'last_update_ts': _ts('jumpLastUpdate'), }, 'remote_station_ts': _ts('remoteStationDate'), 'last_respec_ts': _ts('lastRespecDate'), 'last_timed_respec_ts': _ts('lastTimedRespec'), 'free_respecs': _int('freeRespecs'), 'free_skillpoints': _int('freeSkillPoints'), 'home_station_id': _int('homeStationID'), 'jumpclone': { 'jump_ts': _ts('cloneJumpDate'), }, } for attr in ('intelligence', 'memory', 'charisma', 'perception', 'willpower'): result['attributes'][attr] = {} base = int(api_result.result.findtext('attributes/%s' % attr)) result['attributes'][attr]['base'] = base # NOTE: Removed due to the deprecation of the attribute enhancers section. # Better to break things which rely on this field than return the base. # #result['attributes'][attr]['total'] = base # NOTE: CCP has deprecated this in favor of listing the implant typeIDs # as seen below in the 'implants' section. # #bonus = api_result.result.find('attributeEnhancers/%sBonus' % attr) #if bonus is not None: # mod = int(bonus.findtext('augmentatorValue')) # result['attributes'][attr]['total'] += mod # result['attributes'][attr]['bonus'] = { # 'name': bonus.findtext('augmentatorName'), # 'value': mod, # } rowsets = {} for rowset in api_result.result.findall('rowset'): key = rowset.attrib['name'] rowsets[key] = rowset for implant in rowsets['implants']: a = implant.attrib result['implants'][int(a['typeID'])] = a['typeName'] jumpclone_implants = {} for implant in rowsets['jumpCloneImplants']: a = implant.attrib jumpclone_id = int(a['jumpCloneID']) implants = jumpclone_implants.setdefault(jumpclone_id, {}) implants[int(a['typeID'])] = a['typeName'] result['jumpclone']['clones'] = {} for jumpclone in rowsets['jumpClones']: a = jumpclone.attrib jumpclone_id = int(a['jumpCloneID']) location_id = int(a['locationID']) # This is keyed off location_id because it simplifies a # common lookup ("what systems do I have jumpclones in") result['jumpclone']['clones'][location_id] = { 'id': jumpclone_id, 'name': a['cloneName'], 'type_id': int(a['typeID']), 'location_id': location_id, 'implants': jumpclone_implants.get(jumpclone_id, {}) } result['skills'] = {} result['skillpoints'] = 0 for skill in rowsets['skills']: a = skill.attrib skill_id = int(a['typeID']) sp = int(a['skillpoints']) result['skills'][skill_id] = { 'id': skill_id, 'skillpoints': sp, 'level': int(a['level']), 'published': a['published'] == '1', } result['skillpoints'] += sp result['roles'] = {} for our_role, ccp_role in constants.Char().corp_roles.items(): result['roles'][our_role] = {} for role in rowsets[ccp_role]: a = role.attrib role_id = int(a['roleID']) result['roles'][our_role][role_id] = { 'id': role_id, 'name': a['roleName'], } result['titles'] = {} for title in rowsets['corporationTitles']: a = title.attrib title_id = int(a['titleID']) result['titles'][title_id] = { 'id': title_id, 'name': a['titleName'], } return api.APIResult(result, api_result.timestamp, api_result.expires)
def corporation_sheet(self, corp_id=None, api_result=None): """Get information about a corporation. NOTE: This method may be called with or without specifying a corporation ID. If a corporation ID is specified, the public information for that corporation will be returned, and no api key is necessary. If a corporation ID is *not* specified, a corp api key *must* be provided, and the private information for that corporation will be returned along with the public info. """ def get_logo_details(logo_result): _str, _int, _float, _bool, _ts = api.elem_getters(logo_result) return { 'graphic_id': _int('graphicID'), 'shapes': [ { 'id': _int('shape1'), 'color': _int('color1') }, { 'id': _int('shape2'), 'color': _int('color2') }, { 'id': _int('shape3'), 'color': _int('color3') }, ], } _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'id': _int('corporationID'), 'name': _str('corporationName'), 'ticker': _str('ticker'), 'ceo': { 'id': _int('ceoID'), 'name': _str('ceoName'), }, 'hq': { 'id': _int('stationID'), 'name': _str('stationName'), }, 'description': _str('description'), 'url': _str('url'), 'alliance': { 'id': _int('allianceID') or None, 'name': _str('allianceName') or None, }, 'tax_percent': _float('taxRate'), 'members': { 'current': _int('memberCount'), }, 'shares': _int('shares'), 'logo': get_logo_details(api_result.result.find('logo')), } if corp_id is None: result['members']['limit'] = _int('memberLimit') rowsets = dict((r.attrib['name'], r) for r in api_result.result.findall('rowset')) division_types = { 'hangars': 'divisions', 'wallets': 'walletDivisions', } for key, rowset_name in division_types.items(): divisions = {} for row in rowsets[rowset_name].findall('row'): a = row.attrib divisions[int(a['accountKey'])] = a['description'] result[key] = divisions return api.APIResult(result, api_result.timestamp, api_result.expires)
def starbase_details(self, starbase_id, api_result=None): """Returns details about the specified POS.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) general_settings = api_result.result.find('generalSettings') combat_settings = api_result.result.find('combatSettings') def get_fuel_bay_perms(settings): # Two 2-bit fields usage_flags = int(settings.find('usageFlags').text) take_value = usage_flags % 4 view_value = (usage_flags >> 2) % 4 return { 'view': constants.Corp.pos_permission_entities[view_value], 'take': constants.Corp.pos_permission_entities[take_value], } def get_deploy_perms(settings): # Four 2-bit fields deploy_flags = int(settings.find('deployFlags').text) anchor_value = (deploy_flags >> 6) % 4 unanchor_value = (deploy_flags >> 4) % 4 online_value = (deploy_flags >> 2) % 4 offline_value = deploy_flags % 4 return { 'anchor': constants.Corp.pos_permission_entities[anchor_value], 'unanchor': constants.Corp.pos_permission_entities[unanchor_value], 'online': constants.Corp.pos_permission_entities[online_value], 'offline': constants.Corp.pos_permission_entities[offline_value], } def get_combat_settings(settings): result = { 'standings_owner_id': int(settings.find('useStandingsFrom').attrib['ownerID']), 'hostility': {}, } hostility = result['hostility'] # TODO(ayust): The fields returned by the API don't completely match up with # the fields available in-game. May want to revisit this in the future. standing = settings.find('onStandingDrop') hostility['standing'] = { 'threshold': float(standing.attrib['standing']) / 100, 'enabled': standing.attrib.get('enabled') != '0', } sec_status = settings.find('onStatusDrop') hostility['sec_status'] = { 'threshold': float(sec_status.attrib['standing']) / 100, 'enabled': sec_status.attrib.get('enabled') != '0', } hostility['aggression'] = { 'enabled': settings.find('onAggression').get('enabled') != '0', } hostility['war'] = { 'enabled': settings.find('onCorporationWar').get('enabled') != '0', } return result result = { 'state': constants.Corp.pos_states[_int('state')], 'state_ts': _ts('stateTimestamp'), 'online_ts': _ts('onlineTimestamp'), 'permissions': { 'fuel': get_fuel_bay_perms(general_settings), 'deploy': get_deploy_perms(general_settings), 'forcefield': { 'corp': general_settings.find('allowCorporationMembers').text == '1', 'alliance': general_settings.find('allowAllianceMembers').text == '1', }, }, 'combat': get_combat_settings(combat_settings), 'fuel': {}, } rowset = api_result.result.find('rowset') for row in rowset.findall('row'): a = row.attrib result['fuel'][int(a['typeID'])] = int(a['quantity']) return api.APIResult(result, api_result.timestamp, api_result.expires)
def character_sheet(self, api_result=None): """Returns attributes relating to a specific character.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { 'id': _int('characterID'), 'name': _str('name'), 'create_ts': _ts('DoB'), 'race': _str('race'), 'bloodline': _str('bloodLine'), 'ancestry': _str('ancestry'), 'gender': _str('gender'), 'corp': { 'id': _int('corporationID'), 'name': _str('corporationName'), }, 'alliance': { 'id': _int('allianceID') or None, 'name': _str('allianceName'), }, 'balance': _float('balance'), 'attributes': {}, 'implants': {}, 'jump': { 'activation_ts': _ts('jumpActivation'), 'fatigue_ts': _ts('jumpFatigue'), 'last_update_ts': _ts('jumpLastUpdate'), }, 'remote_station_ts': _ts('remoteStationDate'), 'last_respec_ts': _ts('lastRespecDate'), 'last_timed_respec_ts': _ts('lastTimedRespec'), 'free_respecs': _int('freeRespecs'), 'free_skillpoints': _int('freeSkillPoints'), 'home_station_id': _int('homeStationID'), 'jumpclone': { 'jump_ts': _ts('cloneJumpDate'), }, } for attr in ('intelligence', 'memory', 'charisma', 'perception', 'willpower'): result['attributes'][attr] = {} base = int(api_result.result.findtext('attributes/%s' % attr)) result['attributes'][attr]['base'] = base # NOTE: Removed due to the deprecation of the attribute enhancers section. # Better to break things which rely on this field than return the base. # #result['attributes'][attr]['total'] = base # NOTE: CCP has deprecated this in favor of listing the implant typeIDs # as seen below in the 'implants' section. # #bonus = api_result.result.find('attributeEnhancers/%sBonus' % attr) #if bonus is not None: # mod = int(bonus.findtext('augmentatorValue')) # result['attributes'][attr]['total'] += mod # result['attributes'][attr]['bonus'] = { # 'name': bonus.findtext('augmentatorName'), # 'value': mod, # } rowsets = {} for rowset in api_result.result.findall('rowset'): key = rowset.attrib['name'] rowsets[key] = rowset for implant in rowsets['implants']: a = implant.attrib result['implants'][int(a['typeID'])] = a['typeName'] jumpclone_implants = {} for implant in rowsets['jumpCloneImplants']: a = implant.attrib jumpclone_id = int(a['jumpCloneID']) implants = jumpclone_implants.setdefault(jumpclone_id, {}) implants[int(a['typeID'])] = a['typeName'] result['jumpclone']['clones'] = {} for jumpclone in rowsets['jumpClones']: a = jumpclone.attrib jumpclone_id = int(a['jumpCloneID']) location_id = int(a['locationID']) # This is keyed off location_id because it simplifies a # common lookup ("what systems do I have jumpclones in") result['jumpclone']['clones'][location_id] = { 'id': jumpclone_id, 'name': a['cloneName'], 'type_id': int(a['typeID']), 'location_id': location_id, 'implants': jumpclone_implants.get(jumpclone_id, {}) } result['skills'] = [] result['skillpoints'] = 0 for skill in rowsets['skills']: a = skill.attrib sp = int(a['skillpoints']) result['skills'].append({ 'id': int(a['typeID']), 'skillpoints': sp, 'level': int(a['level']), 'published': a['published'] == '1', }) result['skillpoints'] += sp result['roles'] = {} for our_role, ccp_role in constants.Char().corp_roles.items(): result['roles'][our_role] = {} for role in rowsets[ccp_role]: a = role.attrib role_id = int(a['roleID']) result['roles'][our_role][role_id] = { 'id': role_id, 'name': a['roleName'], } result['titles'] = {} for title in rowsets['corporationTitles']: a = title.attrib title_id = int(a['titleID']) result['titles'][title_id] = { 'id': title_id, 'name': a['titleName'], } return api.APIResult(result, api_result.timestamp, api_result.expires)
def character_sheet(self, api_result=None): """Returns attributes relating to a specific character.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { "id": _int("characterID"), "name": _str("name"), "create_ts": _ts("DoB"), "race": _str("race"), "bloodline": _str("bloodLine"), "ancestry": _str("ancestry"), "gender": _str("gender"), "corp": {"id": _int("corporationID"), "name": _str("corporationName")}, "alliance": {"id": _int("allianceID") or None, "name": _str("allianceName")}, "clone": {"name": _str("cloneName"), "skillpoints": _int("cloneSkillPoints")}, "balance": _float("balance"), "attributes": {}, "implants": {}, "jump": { "activation_ts": _ts("jumpActivation"), "fatigue_ts": _ts("jumpFatigue"), "last_update_ts": _ts("jumpLastUpdate"), }, "remote_station_ts": _ts("remoteStationDate"), "last_respec_ts": _ts("lastRespecDate"), "last_timed_respec_ts": _ts("lastTimedRespec"), "free_respecs": _int("freeRespecs"), "free_skillpoints": _int("freeSkillPoints"), "home_station_id": _int("homeStationID"), "jumpclone": {"jump_ts": _ts("cloneJumpDate")}, } for attr in ("intelligence", "memory", "charisma", "perception", "willpower"): result["attributes"][attr] = {} base = int(api_result.result.findtext("attributes/%s" % attr)) result["attributes"][attr]["base"] = base # NOTE: Removed due to the deprecation of the attribute enhancers section. # Better to break things which rely on this field than return the base. # # result['attributes'][attr]['total'] = base # NOTE: CCP has deprecated this in favor of listing the implant typeIDs # as seen below in the 'implants' section. # # bonus = api_result.result.find('attributeEnhancers/%sBonus' % attr) # if bonus is not None: # mod = int(bonus.findtext('augmentatorValue')) # result['attributes'][attr]['total'] += mod # result['attributes'][attr]['bonus'] = { # 'name': bonus.findtext('augmentatorName'), # 'value': mod, # } rowsets = {} for rowset in api_result.result.findall("rowset"): key = rowset.attrib["name"] rowsets[key] = rowset for implant in rowsets["implants"]: a = implant.attrib result["implants"][int(a["typeID"])] = a["typeName"] jumpclone_implants = {} for implant in rowsets["jumpCloneImplants"]: a = implant.attrib jumpclone_id = int(a["jumpCloneID"]) implants = jumpclone_implants.setdefault(jumpclone_id, {}) implants[int(a["typeID"])] = a["typeName"] result["jumpclone"]["clones"] = {} for jumpclone in rowsets["jumpClones"]: a = jumpclone.attrib jumpclone_id = int(a["jumpCloneID"]) location_id = int(a["locationID"]) # This is keyed off location_id because it simplifies a # common lookup ("what systems do I have jumpclones in") result["jumpclone"]["clones"][location_id] = { "id": jumpclone_id, "name": a["cloneName"], "type_id": int(a["typeID"]), "location_id": location_id, "implants": jumpclone_implants.get(jumpclone_id, {}), } result["skills"] = [] result["skillpoints"] = 0 for skill in rowsets["skills"]: a = skill.attrib sp = int(a["skillpoints"]) result["skills"].append( { "id": int(a["typeID"]), "skillpoints": sp, "level": int(a["level"]), "published": a["published"] == "1", } ) result["skillpoints"] += sp result["roles"] = {} for our_role, ccp_role in constants.Char().corp_roles.items(): result["roles"][our_role] = {} for role in rowsets[ccp_role]: a = role.attrib role_id = int(a["roleID"]) result["roles"][our_role][role_id] = {"id": role_id, "name": a["roleName"]} result["titles"] = {} for title in rowsets["corporationTitles"]: a = title.attrib title_id = int(a["titleID"]) result["titles"][title_id] = {"id": title_id, "name": a["titleName"]} return api.APIResult(result, api_result.timestamp, api_result.expires)
def skill_tree(self, api_result=None): """Return a dict of all available skill groups.""" rowset = api_result.result.find("rowset") # skillGroups results = {} name_cache = {} for row in rowset.findall("row"): # the skill group data g = row.attrib group = {"id": int(g["groupID"]), "name": g["groupName"], "skills": {}} # Because :ccp: groups can sometimes be listed # multiple times with different skills, and the # correct result is to add the contents together group = results.get(group["id"], group) # now get the actual skill data skills_rs = row.find("rowset") # skills for skill_row in skills_rs.findall("row"): a = skill_row.attrib _str, _int, _float, _bool, _ts = api.elem_getters(skill_row) req_attrib = skill_row.find("requiredAttributes") skill = { "id": int(a["typeID"]), "group_id": int(a["groupID"]), "name": a["typeName"], "published": (a["published"] == "1"), "description": _str("description"), "rank": _int("rank"), "required_skills": {}, "bonuses": {}, "attributes": { "primary": api.get_named_value(req_attrib, "primaryAttribute"), "secondary": api.get_named_value(req_attrib, "secondaryAttribute"), }, } name_cache[skill["id"]] = skill["name"] # Check each rowset inside the skill, and branch based on the name attribute for sub_rs in skill_row.findall("rowset"): if sub_rs.attrib["name"] == "requiredSkills": for sub_row in sub_rs.findall("row"): b = sub_row.attrib req = {"level": int(b["skillLevel"]), "id": int(b["typeID"])} skill["required_skills"][req["id"]] = req elif sub_rs.attrib["name"] == "skillBonusCollection": for sub_row in sub_rs.findall("row"): b = sub_row.attrib bonus = {"type": b["bonusType"], "value": float(b["bonusValue"])} skill["bonuses"][bonus["type"]] = bonus group["skills"][skill["id"]] = skill results[group["id"]] = group # Second pass to fill in required skill names for group in results.values(): for skill in group["skills"].values(): for skill_id, skill_info in skill["required_skills"].items(): skill_info["name"] = name_cache.get(skill_id) return api.APIResult(results, api_result.timestamp, api_result.expires)
def character_sheet(self, api_result=None): """Returns attributes relating to a specific character.""" _str, _int, _float, _bool, _ts = api.elem_getters(api_result.result) result = { "id": _int("characterID"), "name": _str("name"), "create_ts": _ts("DoB"), "race": _str("race"), "bloodline": _str("bloodLine"), "ancestry": _str("ancestry"), "gender": _str("gender"), "corp": {"id": _int("corporationID"), "name": _str("corporationName")}, "alliance": {"id": _int("allianceID") or None, "name": _str("allianceName")}, "clone": {"name": _str("cloneName"), "skillpoints": _int("cloneSkillPoints")}, "balance": _float("balance"), "attributes": {}, } for attr in ("intelligence", "memory", "charisma", "perception", "willpower"): result["attributes"][attr] = {} base = int(api_result.result.findtext("attributes/%s" % attr)) result["attributes"][attr]["base"] = base result["attributes"][attr]["total"] = base bonus = api_result.result.find("attributeEnhancers/%sBonus" % attr) if bonus is not None: mod = int(bonus.findtext("augmentatorValue")) result["attributes"][attr]["total"] += mod result["attributes"][attr]["bonus"] = {"name": bonus.findtext("augmentatorName"), "value": mod} rowsets = {} for rowset in api_result.result.findall("rowset"): key = rowset.attrib["name"] rowsets[key] = rowset result["skills"] = [] result["skillpoints"] = 0 for skill in rowsets["skills"]: a = skill.attrib sp = int(a["skillpoints"]) result["skills"].append( { "id": int(a["typeID"]), "skillpoints": sp, "level": int(a["level"]), "published": a["published"] == "1", } ) result["skillpoints"] += sp result["certificates"] = set() for cert in rowsets["certificates"]: result["certificates"].add(int(cert.attrib["certificateID"])) result["roles"] = {} for our_role, ccp_role in constants.Char().corp_roles.items(): result["roles"][our_role] = {} for role in rowsets[ccp_role]: a = role.attrib role_id = int(a["roleID"]) result["roles"][our_role][role_id] = {"id": role_id, "name": a["roleName"]} result["titles"] = {} for title in rowsets["corporationTitles"]: a = title.attrib title_id = int(a["titleID"]) result["titles"][title_id] = {"id": title_id, "name": a["titleName"]} return api.APIResult(result, api_result.timestamp, api_result.expires)