Example #1
0
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()
Example #2
0
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)
Example #3
0
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)
Example #4
0
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()