def fetch_starbaselist(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(corporation.owner_key) try: api_data = auth.corp.StarbaseList(characterID=corporation.owner_key.characterID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return posIDs = handler.autoparse_list( api_data.starbases, Starbase, unique_together=("itemID",), extra_selectors={"owner": corporation}, owner=corporation, pre_save=True, ) Starbase.objects.filter(owner=corporation).exclude(pk__in=posIDs).delete() target.updated(api_data)
def fetch_industryjobshistory(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.IndustryJobsHistory(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return handler.autoparse_list(api_data.jobs, IndustryJobHistory, unique_together=('jobID', ), extra_selectors={'owner': character}, owner=character) target.updated(api_data) character_industry_jobs_history_updated.send(IndustryJobHistory, characterID=character.pk)
def fetch_assetlist(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(corporation.owner_key) try: api_data = auth.corp.AssetList(characterID=corporation.owner_key.characterID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return assetlist = AssetList(owner=corporation, retrieved=api_data._meta.currentTime) assetlist.items = handler.asset_parser(api_data.assets, Asset, corporation) assetlist.save() handler = CorporationAssetHandler() handler.invalidate_entity(corporation.pk) target.updated(api_data)
def fetch_wallettransactions(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.WalletTransactions(characterID=target.owner, rowCount=2560) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return handler.autoparse_list(api_data.transactions, WalletTransaction, unique_together=('transactionID', ), extra_selectors={'owner': character}, owner=character, exclude=['transactionType', 'transactionFor'], pre_save=True, immutable=True) target.updated(api_data)
def fetch_blueprints(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.Blueprints(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return blueprintsIDs = handler.autoparse_list( api_data.blueprints, Blueprint, unique_together=('itemID', ), extra_selectors={'owner': character}, owner=character, pre_save=True) Blueprint.objects.filter(owner=character) \ .exclude(pk__in=blueprintsIDs).delete() target.updated(api_data)
def fetch_skill_in_training(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.SkillInTraining(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return obj = handler.autoparseObj(api_data, SkillInTraining, extra_selectors={'owner': character}, owner=character, exclude=('currentTQTime',)) obj.currentTQTime = api_data.currentTQTime.data obj.save() target.updated(api_data)
def fetch_skillqueue(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.SkillQueue(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return skills = handler.autoparse_list(api_data.skillqueue, SkillQueue, unique_together=('typeID', 'level'), extra_selectors={'owner': character}, owner=character, pre_save=True) SkillQueue.objects.filter(owner=character).exclude(pk__in=skills).delete() target.updated(api_data)
def fetch_marketorders(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MarketOrders(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return handler.autoparse_list(api_data.orders, MarketOrder, unique_together=('orderID', ), extra_selectors={'owner': character}, owner=character, pre_save=True) target.updated(api_data)
def fetch_accountbalance(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug('CorporationSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(corporation.owner_key) try: api_data = auth.corp.AccountBalance(characterID=corporation.owner_key.characterID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return handler.autoparse_list(api_data.accounts, AccountBalance, unique_together=('accountKey',), extra_selectors={'owner': corporation}, owner=corporation, pre_save=True) target.updated(api_data)
def fetch_outpostservicedetails(apiupdate_pk, stationID): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.OutpostServiceDetail(itemID=stationID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return outpost_services_ids = handler.autoparse_list( api_data.outpostServiceDetails, OutpostService, unique_together=("stationID", "serviceName"), extra_selectors={"owner": corporation}, owner=corporation, ) OutpostService.objects.filter(owner=corporation).exclude(pk__in=outpost_services_ids).delete() target.updated(api_data) corporation_outpost_services_updated.send(OutpostService, corporationID=corporation.pk, stationID=stationID)
def fetch_membermedals(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.MemberMedals() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return medal_ids = handler.autoparse_list( api_data.issuedMedals, MemberMedal, unique_together=("medalID", "characterID"), extra_selectors={"owner": corporation}, owner=corporation, ) MemberMedal.objects.filter(owner=corporation).exclude(pk__in=medal_ids).delete() target.updated(api_data) corporation_member_medals_updated.send(MemberMedal, corporationID=corporation.pk)
def fetch_contractbids(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.ContractBids() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return bid_ids, overlap = handler.autoparse_list( api_data.bidList, ContractBid, unique_together=("contractID", "bidID"), extra_selectors={"owner": corporation}, owner=corporation, immutable=True, ) target.updated(api_data) # Only trigger if there are new bids for bid in ContractBid.objects.filter(pk__in=bid_ids): corporation_contract_bids_new_bid.send( ContractBid, corporationID=corporation.pk, contractID=bid.contractID, bid_pk=bid.pk ) corporation_contract_bids_updated.send(ContractBid, corporationID=corporation.pk)
def fetch_assetlist(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.AssetList(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return assetlist = AssetList(owner=character, retrieved=api_data._meta.currentTime) assetlist.items, itemIDs_with_names = handler.asset_parser( api_data.assets, Asset, character, target) assetlist.save() if target.apikey.can_call( APICall.objects.get(type='Character', name='Locations')): names_registered = 0 log.debug('Fetching the item name of {0} items.'.format( len(itemIDs_with_names))) for block in _blocker(itemIDs_with_names, 1000): try: if target.apikey.type == 'Account': api_data = auth.char.Locations(characterID=character.pk, IDs=','.join(block)) else: api_data = auth.char.Locations(IDs=','.join(block)) except Exception, ex: log.warning( 'Could not fetch names for itemIDs "{0}", with APIKey {1}.\n{2}' .format(block, target.apikey.pk, format_exc(ex))) continue IDs = handler.autoparse_list(api_data.locations, ItemLocationName, unique_together=('itemID', ), extra_selectors={'owner': character}, owner=character, pre_save=True) names_registered += len(IDs) old_names = ItemLocationName.objects.filter(owner=character).exclude( pk__in=itemIDs_with_names) log.debug('Fetched {0} names and deleted {1} for "{2}"'.format( names_registered, old_names.count(), character)) old_names.delete()
def fetch_mailinglists(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailingLists(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return listIDs = handler.autoparse_shared_list(api_data.mailingLists, MailingList, ('listID', ), character, pre_save=True) unsubscribed = character.mailinglist_set.exclude(listID__in=listIDs) for desub in unsubscribed: desub.owners.remove(character) target.updated(api_data)
def fetch_contracts(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.Contracts() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return contract_ids = handler.autoparse_list( api_data.contractList, Contract, unique_together=("contractID",), extra_selectors={"owner": corporation}, owner=corporation, ) target.updated(api_data) corporation_contracts_updated.send(Contract, corporationID=corporation.pk) for id in contract_ids: contract = Contract.objects.get(pk=id) if contract.get_items().count() == 0: app.send_task("corporation.fetch_contractitems", [target.pk, contract.pk])
def fetch_mailinglists(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailingLists(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return listIDs = handler.autoparse_shared_list(api_data.mailingLists, MailingList, ('listID',), character, pre_save=True) unsubscribed = character.mailinglist_set.exclude(listID__in=listIDs) for desub in unsubscribed: desub.owners.remove(character) target.updated(api_data)
def fetch_skill_in_training(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.SkillInTraining(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return obj = handler.autoparseObj(api_data, SkillInTraining, extra_selectors={'owner': character}, owner=character, exclude=('currentTQTime', )) obj.currentTQTime = api_data.currentTQTime.data obj.save() target.updated(api_data)
def fetch_marketorders(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.MarketOrders() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return handler.autoparse_list( api_data.orders, MarketOrder, unique_together=("orderID",), extra_selectors={"owner": corporation}, owner=corporation, ) target.updated(api_data) corporation_market_orders_updated.send(MarketOrder, corporationID=corporation.pk)
def fetch_membertracking(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.MemberTracking(characterID=target.apikey.characterID, extended=1) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return memberIDs = handler.autoparse_list( api_data.members, MemberTracking, unique_together=("characterID",), extra_selectors={"owner": corporation}, owner=corporation, pre_save=True, ) MemberTracking.objects.filter(owner=corporation).exclude(pk__in=memberIDs).delete() target.updated(api_data) corporation_member_tracking_updated.send(Starbase, corporationID=corporation.pk)
def fetch_facilities(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.Facilities() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return facility_ids = handler.autoparse_list( api_data.facilities, Facility, unique_together=("facilityID",), extra_selectors={"owner": corporation}, owner=corporation, ) Facility.objects.filter(owner=corporation).exclude(pk__in=facility_ids).delete() target.updated(api_data) corporation_facilities_updated.send(Facility, corporationID=corporation.pk)
def fetch_membersecuritylog(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.MemberSecurityLog() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return handler.autoparse_list( api_data.roleHistory, MemberSecurityLog, unique_together=("changeTime", "characterID", "roleLocationType"), extra_selectors={"owner": corporation}, owner=corporation, immutable=True, ) target.updated(api_data) corporation_member_security_log_updated.send(MemberSecurityLog, corporationID=corporation.pk)
def fetch_blueprints(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug('CorporationSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(corporation.owner_key) try: api_data = auth.corp.Blueprints(characterID=corporation.owner_key.characterID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return blueprintsIDs = handler.autoparse_list(api_data.blueprints, Blueprint, unique_together=('itemID',), extra_selectors={'owner': corporation}, owner=corporation, pre_save=True) Blueprint.objects.filter(owner=corporation) \ .exclude(pk__in=blueprintsIDs).delete() target.updated(api_data)
def fetch_industryjobshistory(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.IndustryJobsHistory(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return handler.autoparse_list(api_data.jobs, IndustryJobHistory, unique_together=('jobID',), extra_selectors={'owner': character}, owner=character) target.updated(api_data) character_industry_jobs_history_updated.send(IndustryJobHistory, characterID=character.pk)
def fetch_wallettransactions(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.WalletTransactions(characterID=target.owner, rowCount=2560) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return handler.autoparse_list(api_data.transactions, WalletTransaction, unique_together=('transactionID',), extra_selectors={'owner': character}, owner=character, exclude=['transactionType', 'transactionFor'], pre_save=True) target.updated(api_data)
def fetch_mails(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailMessages(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return mails = handler.autoparse_shared_list(api_data.messages, MailMessage, ('messageID',), character, pre_save=True) unfetched_mails = MailMessage.objects.filter( owners__in=[character.pk], pk__in=mails, broken=False, raw_message=None) EveName.objects.populate() if unfetched_mails.count() > 0: mail_bodies = auth.char.MailBodies(characterID=target.owner, IDs=[mail.messageID for mail in unfetched_mails]) for mail_body in mail_bodies.messages: try: mail = MailMessage.objects.get(messageID=mail_body.messageID) mail.raw_message = mail_body.data mail.populate_receivers() mail.save() except MailMessage.DoesNotExist: log.error('Could not fetch message body for messageID {0} belonging to character "{1}".'.format( mail_body.messageID, character )) #except: # note.broken = True # note.save() target.updated(api_data)
def fetch_notifications(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.Notifications(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return notifications, overlaped = handler.autoparse_list( api_data.notifications, Notification, unique_together=('notificationID', ), extra_selectors={'owner': character}, owner=character, pre_save=True, immutable=True) unfetched_notifications = Notification.objects.filter(owner=character, pk__in=notifications, broken=False, raw_message=None) if unfetched_notifications.count() > 0: note_texts = auth.char.NotificationTexts( characterID=target.owner, IDs=[note.notificationID for note in unfetched_notifications]) for note_data in note_texts.notifications: try: note = Notification.objects.get( notificationID=note_data.notificationID, owner=target.owner) note.raw_message = note_data.data note.save() except Notification.DoesNotExist: log.error( 'Could not fetch notification text for notificationID {0} belonging to character "{1}".' .format(note_data.notificationID, character)) # except: # note.broken = True # note.save() target.updated(api_data)
def fetch_assetlist(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.AssetList(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return assetlist = AssetList(owner=character, retrieved=api_data._meta.currentTime) assetlist.items, itemIDs_with_names = handler.asset_parser(api_data.assets, Asset, character, target) assetlist.save() names_registered = 0 log.debug('Fetching the item name of {0} items.'.format(len(itemIDs_with_names))) for block in _blocker(itemIDs_with_names, 1000): try: if target.apikey.type == 'Account': api_data = auth.char.Locations(characterID=character.pk, IDs=','.join(block)) else: api_data = auth.char.Locations(IDs=','.join(block)) except Exception, ex: log.warning('Could not fetch names for itemIDs "{0}", with APIKey {1}.\n{2}'.format( block, target.apikey.pk, format_exc(ex) )) continue IDs = handler.autoparse_list(api_data.locations, ItemLocationName, unique_together=('itemID',), extra_selectors={'owner': character}, owner=character, pre_save=True) names_registered += len(IDs)
def fetch_notifications(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.Notifications(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return notifications = handler.autoparse_list(api_data.notifications, Notification, unique_together=('notificationID',), extra_selectors={'owner': character}, owner=character, pre_save=True) unfetched_notifications = Notification.objects.filter( owner=character, pk__in=notifications, broken=False, raw_message=None) if unfetched_notifications.count() > 0: note_texts = auth.char.NotificationTexts(characterID=target.owner, IDs=[note.notificationID for note in unfetched_notifications]) for note_data in note_texts.notifications: try: note = Notification.objects.get(notificationID=note_data.notificationID, owner=target.owner) note.raw_message = note_data.data note.save() except Notification.DoesNotExist: log.error('Could not fetch notification text for notificationID {0} belonging to character "{1}".'.format( note_data.notificationID, character )) #except: # note.broken = True # note.save() target.updated(api_data)
def fetch_contacts(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.ContactList(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return cIDs = handler.autoparse_list(api_data.contactList, Contact, unique_together=('contactID', ), extra_selectors={ 'owner': character, 'listType': 'Private' }, owner=character, pre_save=True) cIDs.extend( handler.autoparse_list(api_data.corporateContactList, Contact, unique_together=('contactID', ), extra_selectors={ 'owner': character, 'listType': 'Corporate' }, owner=character, pre_save=True)) cIDs.extend( handler.autoparse_list(api_data.allianceContactList, Contact, unique_together=('contactID', ), extra_selectors={ 'owner': character, 'listType': 'Alliance' }, owner=character, pre_save=True)) Contact.objects.filter(owner=character).exclude(pk__in=cIDs).delete() target.updated(api_data)
def fetch_mails(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.MailMessages(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return mails = handler.autoparse_shared_list(api_data.messages, MailMessage, ('messageID', ), character, pre_save=True) unfetched_mails = MailMessage.objects.filter(owners__in=[character.pk], pk__in=mails, broken=False, raw_message=None) EveName.objects.populate() if unfetched_mails.count() > 0: mail_bodies = auth.char.MailBodies( characterID=target.owner, IDs=[mail.messageID for mail in unfetched_mails]) for mail_body in mail_bodies.messages: try: mail = MailMessage.objects.get(messageID=mail_body.messageID) mail.raw_message = mail_body.data mail.populate_receivers() mail.save() except MailMessage.DoesNotExist: log.error( 'Could not fetch message body for messageID {0} belonging to character "{1}".' .format(mail_body.messageID, character)) # except: # note.broken = True # note.save() target.updated(api_data)
def fetch_starbasedetails(apiupdate_pk, starbase_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return try: starbase = Starbase.objects.get(owner=corporation, pk=starbase_pk) except Starbase.DoesNotExist: log.warning( "Received request for starbase details on non-existant starbase {0} owned by {1}.".format( starbase_pk, corporation ) ) return # Unanchored starbases dont have details, just wait for somebody to anchor it first. if starbase.state == 0: return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.StarbaseDetail(itemID=starbase.itemID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return except ServerError: log.error( "ServerError while getting starbase details for {0} with apikey {1}.".format( starbase.itemID, target.apikey.keyID ) ) return fuel_ids = handler.autoparse_list( api_data.fuel, StarbaseFuel, unique_together=("starbase", "typeID"), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"starbase": starbase}, ) StarbaseFuel.objects.filter(owner=corporation, starbase=starbase).exclude(pk__in=fuel_ids).delete() target.updated(api_data) corporation_starbase_details_updated.send(Starbase, corporationID=corporation.pk, starbase_pk=starbase.pk)
def fetch_assetlist(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.AssetList(characterID=target.apikey.characterID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return assetlist = AssetList(owner=corporation, retrieved=api_data._meta.currentTime) assetlist.items, itemIDs_with_names = handler.asset_parser(api_data.assets, Asset, corporation, target) assetlist.save() if target.apikey.can_call(APICall.objects.get(type="Corporation", name="Locations")): names_registered = 0 log.info('Fetching the item name of {0} items for "{1}".'.format(len(itemIDs_with_names), corporation)) for block in _blocker(itemIDs_with_names, 1000): try: api_data = auth.corp.Locations(IDs=",".join(block)) except Exception, ex: log.warning( 'Could not fetch names for itemIDs "{0}", with APIKey {1}.\n{2}'.format( block, target.apikey.pk, format_exc(ex) ) ) continue IDs = handler.autoparse_list( api_data.locations, ItemLocationName, unique_together=("itemID",), extra_selectors={"owner": corporation}, owner=corporation, pre_save=True, ) names_registered += len(IDs) old_names = ItemLocationName.objects.filter(owner=corporation).exclude(pk__in=itemIDs_with_names) log.debug( 'Fetched {0} names and deleted {1} for "{2}"'.format(names_registered, old_names.count(), corporation) ) old_names.delete()
def fetch_npcstandings(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.Standings() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return agent_ids = handler.autoparse_list( api_data.corporationNPCStandings.agents, NPCStanding, unique_together=("fromID",), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"type": "Agent"}, ) corp_ids = handler.autoparse_list( api_data.corporationNPCStandings.NPCCorporations, NPCStanding, unique_together=("fromID",), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"type": "Corporation"}, ) faction_ids = handler.autoparse_list( api_data.corporationNPCStandings.factions, NPCStanding, unique_together=("fromID",), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"type": "Faction"}, ) all_ids = agent_ids + corp_ids + faction_ids NPCStanding.objects.filter(owner=corporation).exclude(pk__in=all_ids).delete() target.updated(api_data) corporation_npc_standings_updated.send(NPCStanding, corporationID=corporation.pk)
def walk_walletjournal(apiupdate_pk, fromID): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format( apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.WalletJournal(characterID=character.pk, rowCount=2560, fromID=fromID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) return new_ids, overlap_ids = handler.autoparse_list( api_data.transactions, WalletJournal, unique_together=['refID'], extra_selectors={'owner': character}, owner=character, pre_save=True, immutable=True) log.info( 'Walked {0} wallet journal entries for character "{1}". {2} new entries, {3} already known' .format( len(new_ids) + len(overlap_ids), character, len(new_ids), len(overlap_ids))) entry_ids = new_ids + overlap_ids if len(api_data.transactions) >= 2560 and len(overlap_ids) < 2560: last_journal_entry = WalletJournal.objects.filter( owner=character, pk__in=entry_ids).aggregate(Min('refID')) log.debug( 'Continuing wallet journal walk for "{0}" from redID {1}.'.format( character, last_journal_entry)) app.send_task('character.walk_walletjournal', [apiupdate_pk, last_journal_entry['refID__min']]) target.updated(api_data)
def fetch_outposts(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.OutpostList() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return outpost_ids = handler.autoparse_list( api_data.corporationStarbases, Outpost, unique_together=("stationID",), extra_selectors={"owner": corporation}, owner=corporation, ) old_entries = Outpost.objects.filter(owner=corporation).exclude(pk__in=outpost_ids) deleted = old_entries.count() old_entries.delete() log.info( 'Updated outposts for corporation "{0}". {1} entries, {2} old entries removed.'.format( corporation, len(outpost_ids), deleted ) ) target.updated(api_data) corporation_outposts_updated.send(Outpost, corporationID=corporation.pk) try: details_call = APICall.objects.get(type="Corporation", name="OutpostServiceDetail") details_target = APIUpdate.objects.get(apicall=details_call, apikey=target.apikey, owner=target.owner) for outpost_pk in outpost_ids: app.send_task("corporation.fetch_outpostservicedetails", (details_target.pk, outpost_pk)) except APICall.DoesNotExist: log.error("Could not find APICall for OutpostServiceDetail.") except APIUpdate.DoesNotExist: log.debug("Key {0} cant call outpost details, so its services remain undetailed.".format(target.apikey.keyID))
def fetch_shareholders(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.ShareHolders() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return char_ids = handler.autoparse_list( api_data.characters, Shareholder, unique_together=("shareholderID", "holder_type"), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"holder_type": "Character"}, ) corp_ids = handler.autoparse_list( api_data.corporations, Shareholder, unique_together=("shareholderID", "holder_type"), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"holder_type": "Corporation"}, ) old_entries = Shareholder.objects.filter(owner=corporation).exclude(pk__in=char_ids + corp_ids) deleted = old_entries.count() old_entries.delete() log.info( 'Updated shareholders for corporation "{0}". {1} entries, {2} old entries removed.'.format( corporation, len(corp_ids) + len(char_ids), deleted ) ) target.updated(api_data) corporation_shareholders_updated.send(Shareholder, corporationID=corporation.pk)
def walk_walletjournal(apiupdate_pk, fromID): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.WalletJournal(characterID=character.pk, rowCount=2560, fromID=fromID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) return new_ids, overlap_ids = handler.autoparse_list(api_data.transactions, WalletJournal, unique_together=['refID'], extra_selectors={'owner': character}, owner=character, pre_save=True, immutable=True) log.info('Walked {0} wallet journal entries for character "{1}". {2} new entries, {3} already known'.format( len(new_ids) + len(overlap_ids), character, len(new_ids), len(overlap_ids) )) entry_ids = new_ids + overlap_ids if len(api_data.transactions) >= 2560 and len(overlap_ids) < 2560: last_journal_entry = WalletJournal.objects.filter(owner=character, pk__in=entry_ids).aggregate(Min('refID')) log.debug('Continuing wallet journal walk for "{0}" from redID {1}.'.format( character, last_journal_entry )) app.send_task('character.walk_walletjournal', [apiupdate_pk, last_journal_entry['refID__min']]) target.updated(api_data)
def fetch_contacts(apiupdate_pk): try: target, character = _get_character_auth(apiupdate_pk) except CharacterSheet.DoesNotExist: log.debug('CharacterSheet for APIUpdate {0} not indexed yet.'.format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning('Target APIUpdate {0} was deleted mid-flight.'.format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.char.ContactList(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner )) target.delete() return cIDs = handler.autoparse_list(api_data.contactList, Contact, unique_together=('contactID',), extra_selectors={'owner': character, 'listType': 'Private'}, owner=character, pre_save=True) cIDs.extend(handler.autoparse_list(api_data.corporateContactList, Contact, unique_together=('contactID',), extra_selectors={'owner': character, 'listType': 'Corporate'}, owner=character, pre_save=True)) cIDs.extend(handler.autoparse_list(api_data.allianceContactList, Contact, unique_together=('contactID',), extra_selectors={'owner': character, 'listType': 'Alliance'}, owner=character, pre_save=True)) Contact.objects.filter(owner=character).exclude(pk__in=cIDs).delete() target.updated(api_data)
def fetch_contactlist(apiupdate_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.ContactList() except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return corp_ids = handler.autoparse_list( api_data.corporateContactList, Contact, unique_together=("contactID",), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"listType": "Corporate"}, ) ally_ids = handler.autoparse_list( api_data.allianceContactList, Contact, unique_together=("contactID",), extra_selectors={"owner": corporation}, owner=corporation, static_defaults={"listType": "Alliance"}, ) old_entries = Contact.objects.filter(owner=corporation).exclude(pk__in=corp_ids + ally_ids) deleted = old_entries.count() old_entries.delete() log.info( 'Updated standings for corporation "{0}". {1} entries, {2} old entries removed.'.format( corporation, len(corp_ids) + len(ally_ids), deleted ) ) target.updated(api_data) corporation_contact_list_updated.send(Contact, corporationID=corporation.pk)
def walk_walletjournal(apiupdate_pk, fromID, accountKey): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.WalletJournal( characterID=target.apikey.characterID, accountKey=accountKey, rowCount=2560, fromID=fromID ) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) return new_ids, overlap_ids = handler.autoparse_list( api_data.entries, WalletJournal, unique_together=["refID"], extra_selectors={"owner": corporation, "accountKey": accountKey}, static_defaults={"accountKey": accountKey}, owner=corporation, pre_save=True, immutable=True, ) log.info( 'Walked {0} wallet journal entries for corporation "{1}". {2} new entries, {3} already known'.format( len(new_ids) + len(overlap_ids), corporation, len(new_ids), len(overlap_ids) ) ) entry_ids = new_ids + overlap_ids if len(api_data.entries) >= 2560 and len(overlap_ids) < 2560: last_journal_entry = WalletJournal.objects.filter( owner=corporation, accountKey=accountKey, refID__in=entry_ids ).aggregate(Min("refID")) app.send_task("corporation.walk_walletjournal", [target.pk, last_journal_entry["refID__min"], accountKey]) target.updated(api_data)
def fetch_contractitems(apiupdate_pk, contract_pk): try: target, corporation = _get_corporation_auth(apiupdate_pk) except CorporationSheet.DoesNotExist: log.debug("CorporationSheet for APIUpdate {0} not indexed yet.".format(apiupdate_pk)) return except APIUpdate.DoesNotExist: log.warning("Target APIUpdate {0} was deleted mid-flight.".format(apiupdate_pk)) return try: contract = Contract.objects.get(pk=contract_pk, owner=corporation) except Contract.DoesNotExist: log.warning( "ContractItems requested for non-existing contractID {0} with APIUpdate {1}.".format( contract_pk, apiupdate_pk ) ) return handler = EveAPIHandler() auth = handler.get_authed_eveapi(target.apikey) try: api_data = auth.corp.ContractItems(contractID=contract.contractID) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format(target.apikey.keyID, target.apikey.owner)) target.delete() return handler.autoparse_list( api_data.itemList, ContractItem, unique_together=("contract", "recordID"), extra_selectors={"owner": corporation}, owner=corporation, immutable=True, static_defaults={"contract": contract}, ) target.updated(api_data) corporation_contract_items_updated.send(ContractItem, corporationID=corporation.pk, contract_pk=contract.pk)
for i in xrange(0, len(itr), size): yield itr[i:i + size] @app.task(name='character.fetch_charactersheet', max_retries=0) def fetch_charactersheet(apiupdate_pk): try: target = APIUpdate.objects.get(pk=apiupdate_pk) except APIUpdate.DoesNotExist, dne: log.error('Target APIUpdate {0} was deleted mid-flight.'.format( apiupdate_pk)) raise dne apikey = target.apikey handler = EveAPIHandler() auth = handler.get_authed_eveapi(apikey) try: sheet = auth.char.CharacterSheet(characterID=target.owner) except AuthenticationError: log.error('AuthenticationError for key "{0}" owned by "{1}"'.format( target.apikey.keyID, target.apikey.owner)) target.delete() return try: character = CharacterSheet.objects.get(characterID=sheet.characterID) # As long as the apikey can get a valid character sheet back from the # eveapi, we'll allow the CS model to change owner and/or key if character.owner_key != apikey: log.warning(