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 post(self, request): apikey_pk = request.data.get('id', None) if apikey_pk: try: key = APIKey.objects.get(pk=apikey_pk, owner=request.user) except APIKey.DoesNotExist: return Response({'msg': 'No such APIKey.'}, status=404) app.send_task('accounting.validate_key', [key.pk]) return Response({'msg': 'Revalidation queued.'}) return Response({'msg': 'No such APIKey'}, status=404)
def fetch_walletjournal(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 log.info('Walking wallet journal for character "{0}".'.format(character)) app.send_task('character.walk_walletjournal', [apiupdate_pk, None])
def fetch_wallettransactions(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 log.info('Walking transactions for corporation "{0}".'.format(corporation)) app.send_task("corporation.walk_wallettransactions", [target.pk, None]) corporation_wallet_journal_updated.send(WalletTransaction, corporationID=corporation.pk)
def fetch_walletjournal(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 log.info('Walking wallet journal for character "{0}".'.format(character)) app.send_task('character.walk_walletjournal', [apiupdate_pk, None])
def fetch_walletjournal(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 for accountKey in (1000, 1001, 1002, 1003, 1004, 1005, 1006): log.info('Walking accountKey {0} for corporation "{1}".'.format(accountKey, corporation)) app.send_task("corporation.walk_walletjournal", [target.pk, None, accountKey]) corporation_wallet_journal_updated.send(WalletJournal, 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 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 handle(self, *args, **options): if APICall.objects.all().count() == 0: result = app.send_task('universe.update_universe', [], **options).get() if result: self.stdout.write('Result: {0}'.format(result)) else: self.stdout.write('Already bootstrapped')
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_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(target.apikey) try: api_data = auth.corp.StarbaseList() 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, ) Starbase.objects.filter(owner=corporation).exclude(pk__in=posIDs).delete() target.updated(api_data) corporation_starbases_updated.send(Starbase, corporationID=corporation.pk) try: details_call = APICall.objects.get(type="Corporation", name="StarbaseDetail") details_target = APIUpdate.objects.get(apicall=details_call, apikey=target.apikey, owner=target.owner) for starbase_pk in posIDs: app.send_task("corporation.fetch_starbasedetails", (details_target.pk, starbase_pk)) except APICall.DoesNotExist: log.error("Could not find APICall for StarbaseDetails.") except APIUpdate.DoesNotExist: log.debug("Key {0} cant call starbase details, so its starbases remain undetailed.".format(target.apikey.keyID))
def update_apidata(sender, instance=None, created=False, **kwargs): if created: app.send_task('accounting.update_corporation_apidata', (instance.pk,))
def trigger_character_wallet_balance(sender, characterID=None, **kwargs): app.send_task('statistics.character_wallet_balance', [characterID])
def trigger_character_asset_worth(sender, characterID=None, **kwargs): app.send_task('statistics.character_asset_worth', [characterID])
def handle(self, *args, **options): app.send_task('accounting.update_capsulers')
def trigger_corporation_account_balance_updated(sender, corporationID=None, **kwargs): app.send_task('statistics.corporation_account_balance', [corporationID])
def update_apidata(sender, instance=None, created=False, **kwargs): if created: app.send_task("accounting.update_character_apidata", (instance.pk,))
def trigger_corporation_asset_worth(sender, corporationID=None, **kwargs): app.send_task("statistics.corporation_asset_worth", [corporationID])
def trigger_corporation_account_balance_updated(sender, corporationID=None, **kwargs): app.send_task("statistics.corporation_account_balance", [corporationID])
def trigger_character_asset_worth(sender, characterID=None, **kwargs): app.send_task("statistics.character_asset_worth", [characterID])
def trigger_character_wallet_balance(sender, characterID=None, **kwargs): app.send_task("statistics.character_wallet_balance", [characterID])
def trigger_corporation_asset_worth(sender, corporationID=None, **kwargs): app.send_task('statistics.corporation_asset_worth', [corporationID])
def handle(self, *args, **options): task_name = args[0] app.send_task(task_name, list(args[1:]), **options)
def validate_key(sender, instance=None, created=False, **kwargs): if created: app.send_task('accounting.validate_key', (instance.pk,))
def sheet_listener(sender, instance=None, created=False, **kwargs): if created: calls = APICall.objects.filter(name__in=('CorporationSheet', 'CharacterSheet')) if instance.apicall in calls: app.send_task('accounting.update_apikey_sheets', (instance.apikey.pk,))
def update_apidata(sender, instance=None, created=False, **kwargs): if created: app.send_task('accounting.update_character_apidata', (instance.pk, ))