Exemplo n.º 1
0
def update_character_affiliations(character_list, chunk_size=990):
    if not character_list:
        return
    changed_corp_counter = 0
    client = EsiClient()
    # chunk into 990 sized lists
    for post_body in [
            character_list[x:x + chunk_size]
            for x in xrange(0, len(character_list), chunk_size)
    ]:
        affiliations, _ = client.post("/v1/characters/affiliation/",
                                      post_body=post_body)
        if not affiliations:
            logger.exception("no affiliations returned from %s" % post_body)
            return
        for affiliation in affiliations:
            char = EVEPlayerCharacter.objects.get(
                pk=affiliation["character_id"])
            if "corporation_id" in affiliation:
                set_corporation_affiliation(affiliation["corporation_id"],
                                            affiliation.get("alliance_id"))

                if char.corporation.id != int(affiliation["corporation_id"]):
                    corp = EVEPlayerCorporation.get_object(
                        affiliation["corporation_id"])
                    changed_corp_counter += 1
                    char.corporation = corp
                    char.save()
    logger.info("updated corporation of %s characters" % changed_corp_counter)
    # now update the publicdata_last_updated in bulk
    EVEPlayerCharacter.objects.filter(pk__in=character_list).update(
        publicdata_last_updated=timezone.now())
Exemplo n.º 2
0
def update_asset_names(character, assets, container_names_only=True):
    """

    :param character:
    :param assets:
    :return:
    """
    item_ids = []
    for item in assets:
        # these conditionals are hacks to skip asset naming for asset categories known to cause issues with the
        # /character/assets/names endpoint. it's not perfect.
        if not item["is_singleton"]:
            continue
        if not (item["location_flag"] == "Deliveries" or item["location_flag"]
                == "Hangar" or item["location_flag"] == "FleetHangar"
                or item["location_flag"] == "AssetSafety"
                or item["location_flag"] == "ShipHangar"):
            continue
        if container_names_only:
            if item["is_in_container"]:
                continue
            if not item["type"].market_group:
                continue
            if item["type"].market_group.parent_id != 379:
                continue

        item_ids.append(item["item_id"])

    pages = int(len(item_ids) / 1000) + 1
    if len(item_ids) % 1000 == 0:
        pages -= 1

    cur_page = 0

    asset_names = []

    client = EsiClient(authenticating_character=character,
                       log_application_errors=False,
                       raise_application_errors=False)
    while cur_page < pages:
        subset = item_ids[cur_page * 1000:(cur_page + 1) * 1000]
        names, err = client.post("/v1/characters/%s/assets/names/" %
                                 (character.pk),
                                 post_body=subset)
        if err == EsiError.EsiApplicationError:
            logger.error(
                "Character %s has assets that are crapping out the names endpoint. total items: %s"
                % (character.pk, len(item_ids)))
            cur_page += 1
            continue

        asset_names += names
        cur_page += 1

    asset_names_dict = {}
    for asset in asset_names:
        asset_names_dict[asset["item_id"]] = asset

    for asset in assets:
        if asset["item_id"] in asset_names_dict:
            asset["name"] = asset_names_dict[asset["item_id"]]["name"]
    return assets