def alliances(self, api_result=None): """Return a dict of all alliances in EVE.""" results = {} rowset = api_result.result.find('rowset') for row in rowset.findall('row'): alliance = { 'name': row.attrib['name'], 'ticker': row.attrib['shortName'], 'id': int(row.attrib['allianceID']), 'executor_id': int(row.attrib['executorCorpID']), 'member_count': int(row.attrib['memberCount']), 'timestamp': api.parse_ts(row.attrib['startDate']), 'member_corps': {}, } corp_rowset = row.find('rowset') for corp_row in corp_rowset.findall('row'): corp_id = int(corp_row.attrib['corporationID']) corp_ts = api.parse_ts(corp_row.attrib['startDate']) alliance['member_corps'][corp_id] = { 'id': corp_id, 'timestamp': corp_ts, } results[alliance['id']] = alliance return api.APIResult(results, api_result.timestamp, api_result.expires)
def parse_contracts(api_result): rowset = api_result.find('rowset') if rowset is None: return results = {} for row in rowset.findall('row'): a = row.attrib contract = { 'id': int(a['contractID']), 'issuer': int(a['issuerID']), 'issuer_corp': int(a['issuerCorpID']), 'assignee': int(a['assigneeID']), 'acceptor': int(a['acceptorID']), 'start': int(a['startStationID']), 'end': int(a['endStationID']), 'type': a['type'], 'status': a['status'], 'corp': a['forCorp'] == '1', 'availability': a['availability'], 'issued': api.parse_ts(a['dateIssued']), 'days': int(a['numDays']), 'price': float(a['price']), 'reward': float(a['reward']), 'collateral': float(a['collateral']), 'buyout': float(a['buyout']), 'volume': float(a['volume']), 'title': a['title'] } contract['expired'] = api.parse_ts(a['dateExpired']) contract['accepted'] = api.parse_ts(a['dateAccepted']) contract['completed'] = api.parse_ts(a['dateCompleted']) results[contract['id']] = contract return results
def parse_contracts(api_result): rowset = api_result.find("rowset") if rowset is None: return results = {} for row in rowset.findall("row"): a = row.attrib contract = { "id": int(a["contractID"]), "issuer": int(a["issuerID"]), "issuer_corp": int(a["issuerCorpID"]), "assignee": int(a["assigneeID"]), "acceptor": int(a["acceptorID"]), "start": int(a["startStationID"]), "end": int(a["endStationID"]), "type": a["type"], "status": a["status"], "corp": a["forCorp"] == "1", "availability": a["availability"], "issued": api.parse_ts(a["dateIssued"]), "days": int(a["numDays"]), "price": float(a["price"]), "reward": float(a["reward"]), "collateral": float(a["collateral"]), "buyout": float(a["buyout"]), "volume": float(a["volume"]), "title": a["title"], } contract["expired"] = api.parse_ts(a["dateExpired"]) contract["accepted"] = api.parse_ts(a["dateAccepted"]) contract["completed"] = api.parse_ts(a["dateCompleted"]) results[contract["id"]] = contract return results
def parse_planetary_pins(api_results): result = {} rowset = api_results.find("rowset") for row in rowset.findall("row"): # shortcut to make the following block less painful a = row.attrib pinID = int(a["pinID"]) result[pinID] = { "id": pinID, "type": {"id": int(a["typeID"]), "name": a["typeName"]}, "schematic": int(a["schematicID"]), "last_launch_ts": api.parse_ts(a["lastLaunchTime"]), "cycle_time": int(a["cycleTime"]), "quantity_per_cycle": int(a["quantityPerCycle"]), "install_ts": api.parse_ts(a["installTime"]), "expiry_ts": api.parse_ts(a["expiryTime"]), "content": { "type": int(a["contentTypeID"]), "name": a["contentTypeName"], "quantity": int(a["contentQuantity"]), }, "loc": {"long": float(a["longitude"]), "lat": float(a["latitude"])}, } return result
def test_parse_contracts(self): self.maxDiff = None api_result = make_api_result("corp/contracts.xml") result = evelink_c.parse_contracts(api_result) self.assertEqual(result, { 5966: { 'id': 5966, 'issuer': 154416088, 'issuer_corp': 154430949, 'assignee': 0, 'acceptor': 0, 'start': 60014659, 'end': 60014659, 'type': 'ItemExchange', 'status': 'Outstanding', 'title': '', 'corp': False, 'availability': 'Public', 'issued': api.parse_ts('2010-02-23 11:28:00'), 'expired': api.parse_ts('2010-03-24 11:28:00'), 'accepted': None, 'completed': None, 'days': 0, 'price': 5000.0, 'reward': 0.0, 'collateral': 0.0, 'buyout': 0.0, 'volume': 0.01, }, 5968: { 'id': 5968, 'issuer': 154416088, 'issuer_corp': 154430949, 'assignee': 154430949, 'acceptor': 0, 'start': 60003760, 'end': 60003760, 'type': 'ItemExchange', 'status': 'Outstanding', 'title': '', 'corp': False, 'availability': 'Private', 'issued': api.parse_ts('2010-02-25 11:33:00'), 'expired': api.parse_ts('2010-03-26 11:33:00'), 'accepted': None, 'completed': None, 'days': 0, 'price': 0.00, 'reward': 0.00, 'collateral': 0.00, 'buyout': 0.00, 'volume': 0.03, } })
def test_parse_contracts(self): api_result, _, _ = make_api_result("corp/contracts.xml") result = evelink_c.parse_contracts(api_result) self.assertEqual( result, { 5966: { 'id': 5966, 'issuer': 154416088, 'issuer_corp': 154430949, 'assignee': 0, 'acceptor': 0, 'start': 60014659, 'end': 60014659, 'type': 'ItemExchange', 'status': 'Outstanding', 'title': '', 'corp': False, 'availability': 'Public', 'issued': api.parse_ts('2010-02-23 11:28:00'), 'expired': api.parse_ts('2010-03-24 11:28:00'), 'accepted': None, 'completed': None, 'days': 0, 'price': 5000.0, 'reward': 0.0, 'collateral': 0.0, 'buyout': 0.0, 'volume': 0.01, }, 5968: { 'id': 5968, 'issuer': 154416088, 'issuer_corp': 154430949, 'assignee': 154430949, 'acceptor': 0, 'start': 60003760, 'end': 60003760, 'type': 'ItemExchange', 'status': 'Outstanding', 'title': '', 'corp': False, 'availability': 'Private', 'issued': api.parse_ts('2010-02-25 11:33:00'), 'expired': api.parse_ts('2010-03-26 11:33:00'), 'accepted': None, 'completed': None, 'days': 0, 'price': 0.00, 'reward': 0.00, 'collateral': 0.00, 'buyout': 0.00, 'volume': 0.03, } })
def parse_industry_jobs(api_result): rowset = api_result.find('rowset') result = {} if rowset is None: return for row in rowset.findall('row'): # shortcut to make the following block less painful a = row.attrib jobID = int(a['jobID']) completed = a['completedCharacterID'] != '0' result[jobID] = { 'activity_id': int(a['activityID']), 'blueprint': { 'id': int(a['blueprintID']), 'location_id': int(a['blueprintLocationID']), 'type': { 'id': int(a['blueprintTypeID']), 'name': a['blueprintTypeName'], }, }, 'completed': completed, 'complete_ts': api.parse_ts(a['completedDate']), 'completor_id': int(a['completedCharacterID']), 'cost': float(a['cost']), 'end_ts': api.parse_ts(a['endDate']), 'facility_id': int(a['facilityID']), 'installer': { 'id': int(a['installerID']), 'name': a['installerName'], }, 'product': { 'type_id': int(a['productTypeID']), 'location_id': int(a['outputLocationID']), 'name': a['productTypeName'], 'probability': float(a['probability']), }, 'runs': int(a['runs']), 'licensed_runs': int(a['licensedRuns']), 'pause_ts': api.parse_ts(a['pauseDate']), 'system': { 'id': int(a['solarSystemID']), 'name': a['solarSystemName'], }, 'station_id': int(a['stationID']), 'begin_ts': api.parse_ts(a['startDate']), 'status': int(a['status']), 'team_id': int(a['teamID']), 'duration': int(a['timeInSeconds']), } return result
def parse_industry_jobs(api_result): rowset = api_result.find('rowset') result = {} if rowset is None: return for row in rowset.findall('row'): # shortcut to make the following block less painful a = row.attrib jobID = int(a['jobID']) result[jobID] = { 'line_id': int(a['assemblyLineID']), 'container_id': int(a['containerID']), 'input': { 'id': int(a['installedItemID']), 'blueprint_type': 'copy' if a['installedItemCopy'] == '1' else 'original', 'location_id': int(a['installedItemLocationID']), 'quantity': int(a['installedItemQuantity']), 'prod_level': int(a['installedItemProductivityLevel']), 'mat_level': int(a['installedItemMaterialLevel']), 'runs_left': int(a['installedItemLicensedProductionRunsRemaining']), 'item_flag': int(a['installedItemFlag']), 'type_id': int(a['installedItemTypeID']), }, 'output': { 'location_id': int(a['outputLocationID']), 'bpc_runs': int(a['licensedProductionRuns']), 'container_location_id': int(a['containerLocationID']), 'type_id': int(a['outputTypeID']), 'flag': int(a['outputFlag']), }, 'runs': int(a['runs']), 'installer_id': int(a['installerID']), 'system_id': int(a['installedInSolarSystemID']), 'multipliers': { 'material': float(a['materialMultiplier']), 'char_material': float(a['charMaterialMultiplier']), 'time': float(a['timeMultiplier']), 'char_time': float(a['charTimeMultiplier']), }, 'container_type_id': int(a['containerTypeID']), 'delivered': a['completed'] == '1', 'finished': a['completedSuccessfully'] == '1', 'status': constants.Industry.job_status[int(a['completedStatus'])], 'activity_id': int(a['activityID']), 'install_ts': api.parse_ts(a['installTime']), 'begin_ts': api.parse_ts(a['beginProductionTime']), 'end_ts': api.parse_ts(a['endProductionTime']), 'pause_ts': api.parse_ts(a['pauseProductionTime']), } return result
def members(self, extended=True, api_result=None): """Returns details about each member of the corporation.""" if api_result is None: args = {} if extended: args['extended'] = 1 api_result = self.api.get('corp/MemberTracking', args) rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): a = row.attrib member = { 'id': int(a['characterID']), 'name': a['name'], 'join_ts': api.parse_ts(a['startDateTime']), 'base': { # TODO(aiiane): Maybe remove this? # It doesn't seem to ever have a useful value. 'id': int(a['baseID']), 'name': a['base'], }, # Note that title does not include role titles, # only ones like 'CEO' 'title': a['title'], } if extended: member.update({ 'logon_ts': api.parse_ts(a['logonDateTime']), 'logoff_ts': api.parse_ts(a['logoffDateTime']), 'location': { 'id': int(a['locationID']), 'name': a['location'], }, 'ship_type': { # "Not available" = -1 ship id; we change to None 'id': max(int(a['shipTypeID']), 0) or None, 'name': a['shipType'] or None, }, 'roles': int(a['roles']), 'can_grant': int(a['grantableRoles']), }) results[member['id']] = member return api.APIResult(results, api_result.timestamp, api_result.expires)
def parse_wallet_transactions(api_result): rowset = api_result.find('rowset') rows = rowset.findall('row') result = [] for row in rows: a = row.attrib entry = { 'timestamp': api.parse_ts(a['transactionDateTime']), 'id': int(a['transactionID']), 'journal_id': int(a['journalTransactionID']), 'quantity': int(a['quantity']), 'type': { 'id': int(a['typeID']), 'name': a['typeName'], }, 'price': float(a['price']), 'client': { 'id': int(a['clientID']), 'name': a['clientName'], }, 'station': { 'id': int(a['stationID']), 'name': a['stationName'], }, 'action': a['transactionType'], 'for': a['transactionFor'], } if 'characterID' in a: entry['char'] = { 'id': int(a['characterID']), 'name': a['characterName'], } result.append(entry) return result
def parse_bookmarks(api_results): result = {} folders = api_results.find('rowset') for row in folders.findall('row'): a = row.attrib folder_id = int(a['folderID']) folder = { 'id': folder_id, 'name': a['folderName'], # "" = toplevel 'bookmarks': {}, } bookmarks = row.find('rowset') for row in bookmarks.findall('row'): a = row.attrib bookmark_id = int(a['bookmarkID']) folder['bookmarks'][bookmark_id] = { 'id': bookmark_id, 'name': a['memo'], 'creator_id': int(a['creatorID']), 'created_ts': api.parse_ts(a['created']), 'item_id': int(a['itemID']), 'type_id': int(a['typeID']), 'location_id': int(a['locationID']), 'x': float(a['x']), 'y': float(a['y']), 'z': float(a['z']), 'note': a['note'], } result[folder_id] = folder return result
def sov_by_system(self): """Get sovereignty info keyed by system.""" api_result = self.api.get('map/Sovereignty') rowset = api_result.find('rowset') results = {} for row in rowset.findall('row'): system = int(row.attrib['solarSystemID']) name = row.attrib['solarSystemName'] faction_id = int(row.attrib['factionID']) or None alliance_id = int(row.attrib['allianceID']) or None corp_id = int(row.attrib['corporationID']) or None results[system] = { 'id': system, 'name': name, 'faction_id': faction_id, 'alliance_id': alliance_id, 'corp_id': corp_id, } data_time = api.parse_ts(api_result.find('dataTime').text) return (results, data_time)
def parse_wallet_transactions(api_result): rowset = api_result.find('rowset') rows = rowset.findall('row') result = [] for row in rows: a = row.attrib entry = { 'timestamp': api.parse_ts(a['transactionDateTime']), 'id': int(a['transactionID']), 'journal_id': int(a['journalTransactionID']), 'quantity': int(a['quantity']), 'type': { 'id': int(a['typeID']), 'name': a['typeName'], }, 'price': float(a['price']), 'client': { 'id': int(a['clientID']), 'name': a['clientName'], }, 'station': { 'id': int(a['stationID']), 'name': a['stationName'], }, 'action': a['transactionType'], 'for': a['transactionFor'], } result.append(entry) return result
def kills_by_system(self, api_result=None): """Get kill counts for systems in the last hour. Returns a tuple of ({system:{killdata}, timestamp). Each {killdata} is {'faction':count, 'ship':count, 'pod':count}. """ rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): system = int(row.attrib['solarSystemID']) faction_kills = int(row.attrib['factionKills']) ship_kills = int(row.attrib['shipKills']) pod_kills = int(row.attrib['podKills']) results[system] = { 'id': system, 'faction': faction_kills, 'ship': ship_kills, 'pod': pod_kills, } data_time = api.parse_ts(api_result.result.find('dataTime').text) return api.APIResult((results, data_time), api_result.timestamp, api_result.expires)
def messages(self, api_result=None): """Returns a list of headers for a character's mail.""" rowset = api_result.result.find('rowset') results = [] for row in rowset.findall('row'): a = row.attrib message = { 'id': int(a['messageID']), 'sender_id': int(a['senderID']), 'timestamp': api.parse_ts(a['sentDate']), 'title': a['title'], 'to': {}, } org_id = a['toCorpOrAllianceID'] message['to']['org_id'] = int(org_id) if org_id else None char_ids = a['toCharacterIDs'] message['to']['char_ids'] = [int(i) for i in char_ids.split(',')] if char_ids else None list_ids = a['toListID'] message['to']['list_ids'] = [int(i) for i in list_ids.split(',')] if list_ids else None results.append(message) return api.APIResult(results, api_result.timestamp, api_result.expires)
def parse_wallet_journal(api_result): rowset = api_result.find('rowset') result = [] for row in rowset.findall('row'): a = row.attrib entry = { 'timestamp': api.parse_ts(a['date']), 'id': int(a['refID']), 'type_id': int(a['refTypeID']), 'party_1': { 'name': a['ownerName1'], 'id': int(a['ownerID1']), }, 'party_2': { 'name': a['ownerName2'], 'id': int(a['ownerID2']), }, 'arg': { 'name': a['argName1'], 'id': int(a['argID1']), }, 'amount': float(a['amount']), 'balance': float(a['balance']), 'reason': a['reason'], 'tax': { 'taxer_id': int(a['taxReceiverID'] or 0), 'amount': float(a['taxAmount'] or 0), }, } result.append(entry) result.sort(key=lambda x: x['id']) return result
def parse_market_orders(api_result): rowset = api_result.find("rowset") rows = rowset.findall("row") result = {} for row in rows: a = row.attrib id = int(a["orderID"]) result[id] = { "id": id, "char_id": int(a["charID"]), "station_id": int(a["stationID"]), "amount": int(a["volEntered"]), "amount_left": int(a["volRemaining"]), "status": constants.Market().order_status[int(a["orderState"])], "type_id": int(a["typeID"]), "range": int(a["range"]), "account_key": int(a["accountKey"]), "duration": int(a["duration"]), "escrow": float(a["escrow"]), "price": float(a["price"]), "type": "buy" if a["bid"] == "1" else "sell", "timestamp": api.parse_ts(a["issued"]), } return result
def parse_market_orders(api_result): rowset = api_result.find('rowset') rows = rowset.findall('row') result = {} for row in rows: a = row.attrib id = int(a['orderID']) result[id] = { 'id': id, 'char_id': int(a['charID']), 'station_id': int(a['stationID']), 'amount': int(a['volEntered']), 'amount_left': int(a['volRemaining']), 'status': constants.Market().order_status[int(a['orderState'])], 'type_id': int(a['typeID']), 'range': int(a['range']), 'account_key': int(a['accountKey']), 'duration': int(a['duration']), 'escrow': float(a['escrow']), 'price': float(a['price']), 'type': 'buy' if a['bid'] == '1' else 'sell', 'timestamp': api.parse_ts(a['issued']), } return result
def calendar_events(self): """Returns the list of upcoming calendar events for a character.""" api_result = self.api.get('char/UpcomingCalendarEvents', {'characterID': self.char_id}) results = {} rowset = api_result.find('rowset') for row in rowset.findall('row'): a = row.attrib event = { 'id': int(a['eventID']), 'owner': { 'id': int(a['ownerID']), 'name': a['ownerName'] or None, }, 'start_ts': api.parse_ts(a['eventDate']), 'title': a['eventTitle'], 'duration': int(a['duration']), 'important': a['importance'] == '1', 'description': a['eventText'], 'response': a['response'], } results[event['id']] = event return results
def parse_planetary_colonies(api_results): result = {} rowset = api_results.find('rowset') for row in rowset.findall('row'): # shortcut to make the following block less painful a = row.attrib planetID = int(a['planetID']) result[planetID] = { 'id': planetID, 'system': { 'id': int(a['solarSystemID']), 'name': a['solarSystemName'], }, 'planet': { 'name': a['planetName'], 'type': int(a['planetTypeID']), 'type_name': a['planetTypeName'], }, 'owner': { 'id': int(a['ownerID']), 'name': a['ownerName'], }, 'last_update': api.parse_ts(a['lastUpdate']), 'upgrade_level': int(a['upgradeLevel']), 'number_of_pins': int(a['numberOfPins']), } return result
def key_info(self, api_result=None): """Returns the details of the API key being used to auth.""" key = api_result.result.find('key') result = { 'access_mask': int(key.attrib['accessMask']), 'type': constants.APIKey.key_types[key.attrib['type']], 'expire_ts': api.parse_ts(key.attrib['expires']) if key.attrib['expires'] else None, 'characters': {}, } rowset = key.find('rowset') for row in rowset.findall('row'): character = { 'id': int(row.attrib['characterID']), 'name': row.attrib['characterName'], 'corp': { 'id': int(row.attrib['corporationID']), 'name': row.attrib['corporationName'], }, } if 'allianceID' in row.attrib: character['alliance'] = { 'id': int(row.attrib['allianceID']), 'name': row.attrib['allianceName'], } else: character['alliance'] = None result['characters'][character['id']] = character 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"]) 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 orders(self): """Return a given character's buy and sell orders.""" api_result = self.api.get('char/MarketOrders', {'characterID': self.char_id}) rowset = api_result.find('rowset') rows = rowset.findall('row') result = {} for row in rows: a = row.attrib id = int(a['orderID']) result[id] = { 'id': id, 'char_id': int(a['charID']), 'station_id': int(a['stationID']), 'amount': int(a['volEntered']), 'amount_left': int(a['volRemaining']), 'status': constants.Market().order_status[int(a['orderState'])], 'type_id': int(a['typeID']), 'range': int(a['range']), 'account_key': int(a['accountKey']), 'duration': int(a['duration']), 'escrow': float(a['escrow']), 'price': float(a['price']), 'type': 'buy' if a['bid'] == '1' else 'sell', 'timestamp': api.parse_ts(a['issued']), } return result
def key_info(self, api_result=None): """Returns the details of the API key being used to auth.""" if api_result is None: api_result = self.api.get('account/APIKeyInfo') key = api_result.result.find('key') result = { 'access_mask': int(key.attrib['accessMask']), 'type': constants.APIKey.key_types[key.attrib['type']], 'expire_ts': api.parse_ts(key.attrib['expires']) if key.attrib['expires'] else None, 'characters': {}, } rowset = key.find('rowset') for row in rowset.findall('row'): character = { 'id': int(row.attrib['characterID']), 'name': row.attrib['characterName'], 'corp': { 'id': int(row.attrib['corporationID']), 'name': row.attrib['corporationName'], }, } result['characters'][character['id']] = character return api.APIResult(result, api_result.timestamp, api_result.expires)
def messages(self, api_result=None): """Returns a list of headers for a character's mail.""" rowset = api_result.result.find("rowset") results = [] for row in rowset.findall("row"): a = row.attrib message = { "id": int(a["messageID"]), "sender_id": int(a["senderID"]), "timestamp": api.parse_ts(a["sentDate"]), "title": a["title"], "to": {}, } org_id = a["toCorpOrAllianceID"] message["to"]["org_id"] = int(org_id) if org_id else None char_ids = a["toCharacterIDs"] message["to"]["char_ids"] = [int(i) for i in char_ids.split(",")] if char_ids else None list_ids = a["toListID"] message["to"]["list_ids"] = [int(i) for i in list_ids.split(",")] if list_ids else None results.append(message) return api.APIResult(results, api_result.timestamp, api_result.expires)
def messages(self, api_result=None): """Returns a list of headers for a character's mail.""" rowset = api_result.result.find('rowset') results = [] for row in rowset.findall('row'): a = row.attrib message = { 'id': int(a['messageID']), 'sender_id': int(a['senderID']), 'timestamp': api.parse_ts(a['sentDate']), 'title': a['title'], 'to': {}, } org_id = a['toCorpOrAllianceID'] message['to']['org_id'] = int(org_id) if org_id else None char_ids = a['toCharacterIDs'] message['to']['char_ids'] = [int(i) for i in char_ids.split(',') ] if char_ids else None list_ids = a['toListID'] message['to']['list_ids'] = [int(i) for i in list_ids.split(',') ] if list_ids else None results.append(message) return api.APIResult(results, api_result.timestamp, api_result.expires)
def members(self, extended=True, api_result=None): """Returns details about each member of the corporation.""" if api_result is None: args = {} if extended: args['extended'] = 1 api_result = self.api.get('corp/MemberTracking', params=args) rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): a = row.attrib member = { 'id': int(a['characterID']), 'name': a['name'], 'join_ts': api.parse_ts(a['startDateTime']), 'base': { # TODO(aiiane): Maybe remove this? # It doesn't seem to ever have a useful value. 'id': int(a['baseID']), 'name': a['base'], }, # Note that title does not include role titles, # only ones like 'CEO' 'title': a['title'], } if extended: member.update({ 'logon_ts': api.parse_ts(a['logonDateTime']), 'logoff_ts': api.parse_ts(a['logoffDateTime']), 'location': { 'id': int(a['locationID']), 'name': a['location'], }, 'ship_type': { # "Not available" = -1 ship id; we change to None 'id': max(int(a['shipTypeID']), 0) or None, 'name': a['shipType'] or None, }, 'roles': int(a['roles']), 'can_grant': int(a['grantableRoles']), }) results[member['id']] = member return api.APIResult(results, api_result.timestamp, api_result.expires)
def parse_planetary_pins(api_results): result = {} rowset = api_results.find('rowset') for row in rowset.findall('row'): # shortcut to make the following block less painful a = row.attrib pinID = int(a['pinID']) if pinID not in result: result[pinID] = { 'id': pinID, 'type': { 'id': int(a['typeID']), 'name': a['typeName'], }, 'schematic': int(a['schematicID']), 'last_launch_ts': api.parse_ts(a['lastLaunchTime']), 'cycle_time': int(a['cycleTime']), 'quantity_per_cycle': int(a['quantityPerCycle']), 'install_ts': api.parse_ts(a['installTime']), 'expiry_ts': api.parse_ts(a['expiryTime']), 'content': { 'type': int(a['contentTypeID']), 'name': a['contentTypeName'], 'quantity': int(a['contentQuantity']), 'deprecated': 'Use the "contents" field instead', }, 'contents': {}, 'loc': { 'long': float(a['longitude']), 'lat': float(a['latitude']), }, } if a['contentTypeID'] != '0': contentID = int(a['contentTypeID']) result[pinID]['contents'][contentID] = { 'type': contentID, 'name': a['contentTypeName'], 'quantity': int(a['contentQuantity']), } return result
def starbases(self, api_result=None): """Returns information about the corporation's POSes.""" rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): a = row.attrib starbase = { 'id': int(a['itemID']), 'type_id': int(a['typeID']), 'location_id': int(a['locationID']), 'moon_id': int(a['moonID']), 'state': constants.Corp.pos_states[int(a['state'])], 'state_ts': api.parse_ts(a['stateTimestamp']), 'online_ts': api.parse_ts(a['onlineTimestamp']), 'standings_owner_id': int(a['standingOwnerID']), } results[starbase['id']] = starbase return api.APIResult(results, 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: 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 skill_queue(self, api_result=None): """returns the skill queue of the character""" rowset = api_result.result.find('rowset') rows = rowset.findall('row') result = [] for row in rows: a = row.attrib line = { 'position': int(a['queuePosition']), 'type_id': int(a['typeID']), 'level': int(a['level']), 'start_sp': int(a['startSP']), 'end_sp': int(a['endSP']), 'start_ts': api.parse_ts(a['startTime']), 'end_ts': api.parse_ts(a['endTime']), } result.append(line) return api.APIResult(result, api_result.timestamp, api_result.expires)
def skill_queue(self, api_result=None): """returns the skill queue of the character""" rowset = api_result.result.find("rowset") rows = rowset.findall("row") result = [] for row in rows: a = row.attrib line = { "position": int(a["queuePosition"]), "type_id": int(a["typeID"]), "level": int(a["level"]), "start_sp": int(a["startSP"]), "end_sp": int(a["endSP"]), "start_ts": api.parse_ts(a["startTime"]), "end_ts": api.parse_ts(a["endTime"]), } result.append(line) return api.APIResult(result, api_result.timestamp, api_result.expires)
def skill_queue(self): """returns the skill queue of the character""" api_result = self.api.get('char/SkillQueue', {'characterID': self.char_id}) rowset = api_result.find('rowset') rows = rowset.findall('row') result = [] for row in rows: a = row.attrib line = { 'position': int(a['queuePosition']), 'type_id': int(a['typeID']), 'level': int(a['level']), 'start_sp': int(a['startSP']), 'end_sp': int(a['endSP']), 'start_ts': api.parse_ts(a['startTime']), 'end_ts': api.parse_ts(a['endTime']), } result.append(line) return result
def contact_notifications(self, api_result=None): """Returns pending contact notifications.""" results = {} rowset = api_result.result.find("rowset") for row in rowset.findall("row"): a = row.attrib note = { "id": int(a["notificationID"]), "sender": {"id": int(a["senderID"]), "name": a["senderName"]}, "timestamp": api.parse_ts(a["sentDate"]), "data": api.parse_keyval_data(a["messageData"]), } results[note["id"]] = note return api.APIResult(results, api_result.timestamp, api_result.expires)
def alliances(self, api_result=None): """Return a dict of all alliances in EVE.""" results = {} rowset = api_result.result.find("rowset") for row in rowset.findall("row"): alliance = { "name": row.attrib["name"], "ticker": row.attrib["shortName"], "id": int(row.attrib["allianceID"]), "executor_id": int(row.attrib["executorCorpID"]), "member_count": int(row.attrib["memberCount"]), "timestamp": api.parse_ts(row.attrib["startDate"]), "member_corps": {}, } corp_rowset = row.find("rowset") for corp_row in corp_rowset.findall("row"): corp_id = int(corp_row.attrib["corporationID"]) corp_ts = api.parse_ts(corp_row.attrib["startDate"]) alliance["member_corps"][corp_id] = {"id": corp_id, "timestamp": corp_ts} results[alliance["id"]] = alliance return api.APIResult(results, api_result.timestamp, api_result.expires)
def notifications(self, api_result=None): """Returns the message headers for notifications.""" result = {} rowset = api_result.result.find('rowset') for row in rowset.findall('row'): a = row.attrib notification_id = int(a['notificationID']) result[notification_id] = { 'id': notification_id, 'type_id': int(a['typeID']), 'sender_id': int(a['senderID']), 'timestamp': api.parse_ts(a['sentDate']), 'read': a['read'] == '1', } return api.APIResult(result, api_result.timestamp, api_result.expires)
def medals(self, api_result=None): """Returns information about the medals created by a corporation.""" rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): a = row.attrib medal = { 'id': int(a['medalID']), 'creator_id': int(a['creatorID']), 'title': a['title'], 'description': a['description'], 'create_ts': api.parse_ts(a['created']), } results[medal['id']] = medal return api.APIResult(results, 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 member_medals(self, api_result=None): """Returns information about medals assigned to corporation members.""" rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): a = row.attrib award = { 'medal_id': int(a['medalID']), 'char_id': int(a['characterID']), 'reason': a['reason'], 'public': a['status'] == 'public', 'issuer_id': int(a['issuerID']), 'timestamp': api.parse_ts(a['issued']), } results.setdefault(award['char_id'], {})[award['medal_id']] = award return api.APIResult(results, api_result.timestamp, api_result.expires)
def parse_contract_bids(api_result): rowset = api_result.find('rowset') results = [] for row in rowset.findall('row'): a = row.attrib bid = { 'id': int(a['bidID']), 'contract_id': int(a['contractID']), 'bidder_id': int(a['bidderID']), 'timestamp': api.parse_ts(a['dateBid']), 'amount': float(a['amount']), } results.append(bid) return results
def research(self, api_result=None): """Returns information about the agents with whom the character is doing research.""" rowset = api_result.result.find('rowset') rows = rowset.findall('row') result = {} for row in rows: a = row.attrib id = int(a['agentID']) result[id] = { 'id': id, 'skill_id': int(a['skillTypeID']), 'timestamp': api.parse_ts(a['researchStartDate']), 'per_day': float(a['pointsPerDay']), 'remaining': float(a['remainderPoints']), } return api.APIResult(result, api_result.timestamp, api_result.expires)
def contact_notifications(self, api_result=None): """Returns pending contact notifications.""" results = {} rowset = api_result.result.find('rowset') for row in rowset.findall('row'): a = row.attrib note = { 'id': int(a['notificationID']), 'sender': { 'id': int(a['senderID']), 'name': a['senderName'], }, 'timestamp': api.parse_ts(a['sentDate']), 'data': api.parse_keyval_data(a['messageData']), } results[note['id']] = note return api.APIResult(results, api_result.timestamp, api_result.expires)
def jumps_by_system(self, api_result=None): """Get jump counts for systems in the last hour. Returns a tuple of ({system:jumps...}, timestamp). NOTE: Systems with 0 jumps in the last hour are not included! """ rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): system = int(row.attrib['solarSystemID']) jumps = int(row.attrib['shipJumps']) results[system] = jumps data_time = api.parse_ts(api_result.result.find('dataTime').text) return api.APIResult((results, data_time), api_result.timestamp, api_result.expires)
def permissions_log(self, api_result=None): """Returns information about changes to member permissions.""" inverse_role_types = dict( (v, k) for k, v in constants.Corp.role_types.items()) results = [] rowset = api_result.result.find('rowset') for row in rowset.findall('row'): a = row.attrib change = { 'timestamp': api.parse_ts(a['changeTime']), 'recipient': { 'id': int(a['characterID']), 'name': a['characterName'], }, 'issuer': { 'id': int(a['issuerID']), 'name': a['issuerName'], }, 'role_type': inverse_role_types[a['roleLocationType']], 'roles': { 'before': {}, 'after': {}, }, } rowsets = dict( (r.attrib['name'], r) for r in row.findall('rowset')) old, new = change['roles']['before'], change['roles']['after'] for role_row in rowsets['oldRoles'].findall('row'): a = role_row.attrib old[int(a['roleID'])] = a['roleName'] for role_row in rowsets['newRoles'].findall('row'): a = role_row.attrib new[int(a['roleID'])] = a['roleName'] results.append(change) results.sort(key=lambda r: r['timestamp'], reverse=True) 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 parse_wallet_journal(api_result): rowset = api_result.find('rowset') result = [] for row in rowset.findall('row'): a = row.attrib entry = { 'timestamp': api.parse_ts(a['date']), 'id': int(a['refID']), 'type_id': int(a['refTypeID']), 'party_1': { 'name': a['ownerName1'], 'id': int(a['ownerID1']), 'type': int(a['owner1TypeID']), }, 'party_2': { 'name': a['ownerName2'], 'id': int(a['ownerID2']), 'type': int(a['owner2TypeID']), }, 'arg': { 'name': a['argName1'], 'id': int(a['argID1']), }, 'amount': float(a['amount']), 'balance': float(a['balance']), 'reason': a['reason'], # The tax fields might be an empty string, or not present # at all (e.g., for corp wallet records.) Need to handle # both edge cases. 'tax': { 'taxer_id': int(a.get('taxReceiverID') or 0), 'amount': float(a.get('taxAmount') or 0), }, } result.append(entry) result.sort(key=lambda x: x['id']) return result
def calendar_events(self, api_result=None): """Returns the list of upcoming calendar events for a character.""" results = {} rowset = api_result.result.find('rowset') for row in rowset.findall('row'): a = row.attrib event = { 'id': int(a['eventID']), 'owner': { 'id': int(a['ownerID']), 'name': a['ownerName'] or None, }, 'start_ts': api.parse_ts(a['eventDate']), 'title': a['eventTitle'], 'duration': int(a['duration']), 'important': a['importance'] == '1', 'description': a['eventText'], 'response': a['response'], } results[event['id']] = event return api.APIResult(results, api_result.timestamp, api_result.expires)
def sov_by_system(self, api_result=None): """Get sovereignty info keyed by system.""" rowset = api_result.result.find('rowset') results = {} for row in rowset.findall('row'): system = int(row.attrib['solarSystemID']) name = row.attrib['solarSystemName'] faction_id = int(row.attrib['factionID']) or None alliance_id = int(row.attrib['allianceID']) or None corp_id = int(row.attrib['corporationID']) or None results[system] = { 'id': system, 'name': name, 'faction_id': faction_id, 'alliance_id': alliance_id, 'corp_id': corp_id, } data_time = api.parse_ts(api_result.result.find('dataTime').text) return api.APIResult((results, data_time), api_result.timestamp, api_result.expires)
def container_log(self, api_result=None): """Returns a log of actions performed on corporation containers.""" results = [] rowset = api_result.result.find('rowset') def int_or_none(val): return int(val) if val else None for row in rowset.findall('row'): a = row.attrib action = { 'timestamp': api.parse_ts(a['logTime']), 'item': { 'id': int(a['itemID']), 'type_id': int(a['itemTypeID']), }, 'actor': { 'id': int(a['actorID']), 'name': a['actorName'], }, 'location_id': int(a['locationID']), 'action': a['action'], 'details': { # TODO(aiiane): Find a translation for this flag field 'flag': int(a['flag']), 'password_type': a['passwordType'] or None, 'type_id': int_or_none(a['typeID']), 'quantity': int_or_none(a['quantity']), 'config': { 'old': int_or_none(a['oldConfiguration']), 'new': int_or_none(a['newConfiguration']), }, }, } results.append(action) return api.APIResult(results, api_result.timestamp, api_result.expires)
def parse_kills(api_result): rowset = api_result.find('rowset') result = {} for row in rowset.findall('row'): a = row.attrib kill_id = int(a['killID']) result[kill_id] = { 'id': kill_id, 'system_id': int(a['solarSystemID']), 'time': api.parse_ts(a['killTime']), 'moon_id': int(a['moonID']), } victim = row.find('victim') a = victim.attrib result[kill_id]['victim'] = { 'id': int(a['characterID']), 'name': a['characterName'], 'corp': { 'id': int(a['corporationID']), 'name': a['corporationName'], }, 'alliance': { 'id': int(a['allianceID']), 'name': a['allianceName'], }, 'faction': { 'id': int(a['factionID']), 'name': a['factionName'], }, 'damage': int(a['damageTaken']), 'ship_type_id': int(a['shipTypeID']), 'x': float(a['x']), 'y': float(a['y']), 'z': float(a['z']), } result[kill_id]['attackers'] = {} rowsets = {} for rowset in row.findall('rowset'): key = rowset.attrib['name'] rowsets[key] = rowset for attacker in rowsets['attackers'].findall('row'): a = attacker.attrib attacker_id = int(a['characterID']) result[kill_id]['attackers'][attacker_id] = { 'id': attacker_id, 'name': a['characterName'], 'corp': { 'id': int(a['corporationID']), 'name': a['corporationName'], }, 'alliance': { 'id': int(a['allianceID']), 'name': a['allianceName'], }, 'faction': { 'id': int(a['factionID']), 'name': a['factionName'], }, 'sec_status': float(a['securityStatus']), 'damage': int(a['damageDone']), 'final_blow': a['finalBlow'] == '1', 'weapon_type_id': int(a['weaponTypeID']), 'ship_type_id': int(a['shipTypeID']), } def _get_items(rowset): items = [] for item in rowset.findall('row'): a = item.attrib type_id = int(a['typeID']) items.append({ 'id': type_id, 'flag': int(a['flag']), 'dropped': int(a['qtyDropped']), 'destroyed': int(a['qtyDestroyed']), }) containers = item.findall('rowset') for container in containers: items.extend(_get_items(container)) return items result[kill_id]['items'] = _get_items(rowsets['items']) return result