Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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])
Example #10
0
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)
Example #11
0
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)
Example #12
0
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)
Example #13
0
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)
Example #14
0
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)
Example #15
0
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)
Example #16
0
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)
Example #17
0
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)
Example #18
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 #19
0
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)
Example #20
0
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)
Example #21
0
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)
Example #22
0
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)
Example #23
0
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)
Example #24
0
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)
Example #25
0
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)
Example #26
0
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)
Example #27
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 #28
0
def fetch_conquerable_stations():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.eve.ConquerableStationList()
    stationIDs = handler.autoparse_list(apiData.outposts,
                          ConquerableStation,
                          unique_together=('stationID',),
                          pre_save=True)
    log.info('Updated {0} conquerable stations.'.format(len(stationIDs)))
    update, created = UniverseUpdate.objects.get_or_create(apicall='ConquerableStationList')
    update.updated(apiData)
Example #29
0
def fetch_reftypes():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.eve.RefTypes()
    rIDs = handler.autoparse_list(apiData.refTypes,
                          RefType,
                          unique_together=('refTypeID',),
                          pre_save=True)
    log.info('Updated {0} ref types.'.format(len(rIDs)))
    update, created = UniverseUpdate.objects.get_or_create(apicall='RefTypes')
    update.updated(apiData)
Example #30
0
def fetch_sovereignty():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.map.Sovereignty()
    sovIDs = handler.autoparse_list(apiData.solarSystems,
                          Sovereignty,
                          unique_together=('solarSystemID',),
                          pre_save=True)
    log.info('Updated sovereignty for {0} systems.'.format(len(sovIDs)))
    update, created = UniverseUpdate.objects.get_or_create(apicall='Sovereignty')
    update.updated(apiData)
Example #31
0
    def get(self, request):
        handler = EveAPIHandler()
        api = handler.get_eveapi()
        try:
            status = api.server.ServerStatus()
            response = json.dumps({"serverOpen": status.serverOpen,
                                   "onlinePlayers": status.onlinePlayers})

        except:
            response = '{"serverOpen": "False", "onlinePlayers": 0}'
        return HttpResponse(response)
Example #32
0
def fetch_reftypes():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.eve.RefTypes()
    rIDs = handler.autoparse_list(apiData.refTypes,
                                  RefType,
                                  unique_together=('refTypeID', ),
                                  pre_save=True)
    log.info('Updated {0} ref types.'.format(len(rIDs)))
    update, created = UniverseUpdate.objects.get_or_create(apicall='RefTypes')
    update.updated(apiData)
Example #33
0
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)
Example #34
0
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)
Example #35
0
def fetch_sovereignty():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.map.Sovereignty()
    sovIDs = handler.autoparse_list(apiData.solarSystems,
                                    Sovereignty,
                                    unique_together=('solarSystemID', ),
                                    pre_save=True)
    log.info('Updated sovereignty for {0} systems.'.format(len(sovIDs)))
    update, created = UniverseUpdate.objects.get_or_create(
        apicall='Sovereignty')
    update.updated(apiData)
Example #36
0
def fetch_conquerable_stations():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.eve.ConquerableStationList()
    stationIDs = handler.autoparse_list(apiData.outposts,
                                        ConquerableStation,
                                        unique_together=('stationID', ),
                                        pre_save=True)
    log.info('Updated {0} conquerable stations.'.format(len(stationIDs)))
    update, created = UniverseUpdate.objects.get_or_create(
        apicall='ConquerableStationList')
    update.updated(apiData)
Example #37
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()
Example #38
0
    def get(self, request):
        handler = EveAPIHandler()
        api = handler.get_eveapi()
        try:
            status = api.server.ServerStatus()
            response = json.dumps({
                "serverOpen": status.serverOpen,
                "onlinePlayers": status.onlinePlayers
            })

        except:
            response = '{"serverOpen": "False", "onlinePlayers": 0}'
        return HttpResponse(response)
Example #39
0
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)
Example #40
0
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)
Example #41
0
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)
Example #42
0
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)
Example #43
0
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))
Example #44
0
def fetch_apicalls():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.api.CallList()
    cgIDs = handler.autoparse_list(apiData.callGroups,
                                   APICallGroup,
                                   unique_together=('groupID', ),
                                   pre_save=True)
    cIDs = handler.autoparse_list(apiData.calls,
                                  APICall,
                                  unique_together=('accessMask', 'type'),
                                  pre_save=True)

    log.info('Added {0} call groups and {1} calls.'.format(cgIDs, cIDs))
    update, created = UniverseUpdate.objects.get_or_create(apicall='CallList')
    update.updated(apiData)
Example #45
0
def fetch_apicalls():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.api.CallList()
    cgIDs = handler.autoparse_list(apiData.callGroups,
                          APICallGroup,
                          unique_together=('groupID',),
                          pre_save=True)
    cIDs = handler.autoparse_list(apiData.calls,
                          APICall,
                          unique_together=('accessMask', 'type'),
                          pre_save=True)

    log.info('Added {0} call groups and {1} calls.'.format(cgIDs, cIDs))
    update, created = UniverseUpdate.objects.get_or_create(apicall='CallList')
    update.updated(apiData)
Example #46
0
def fetch_alliances():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
    apiData = api.eve.AllianceList()
    allianceIDs = handler.autoparse_list(apiData.alliances,
                                         Alliance,
                                         unique_together=('allianceID', ))
    log.info('Updated {0} alliances.'.format(len(allianceIDs)))
    closed = Alliance.objects.exclude(pk__in=allianceIDs)
    for alliance in closed:
        alliance.closed = True
        alliance.endDate = datetime.now(tz=UTC)
        alliance.save()
    log.info('Closed {0} alliances.'.format(closed.count()))

    update, created = UniverseUpdate.objects.get_or_create(
        apicall='AllianceList')
    update.updated(apiData)
Example #47
0
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)
Example #48
0
def fetch_corporation_names():
    handler = EveAPIHandler()
    api = handler.get_eveapi()
Example #49
0
    Validates an apikey and register all characters or corporations that should
    be updated using this key.

    The process is roughly:
    1. Check the key against the eveapi. Disable if expired or not existing etc
    2. Create an APIUpdate "target" for the services the access mask grants you
       access to, for every character or corporation the key is valid for.

    :param apikey_pk:
    :return:
    """
    try:
        apikey = APIKey.objects.get(pk=apikey_pk)
    except APIKey.DoesNotExist, dne:
        raise dne
    handler = EveAPIHandler()

    api = handler.get_eveapi()
    auth = api.auth(keyID=apikey.keyID, vCode=apikey.vCode)
    try:
        keyinfo = auth.account.APIKeyInfo()
    except AuthenticationError:
        apikey.brokeness += 1
        if apikey.brokeness == 3:
            apikey.expired = True
        apikey.save()
        APIUpdate.objects.filter(apikey=apikey).delete()
        log.info(
            'APIKey "{0}" owned by "{1}" is disabled according to the eveapi.'.
            format(apikey.name, apikey.owner))
        return
Example #50
0
def _blocker(itr, size):
    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: