Exemplo n.º 1
0
def get_character_details_json(GetProfile_res):
    """
    Parse the GetProfile response to get Character information.
    """
    character_details = {}
    temp_dict = {}
    charId_list = []

    # print(GetProfile_res)
    # print(GetProfile_res.headers)

    for key in GetProfile_res['Response']['characters']['data']:
        charId_list.append(key)

    # Populate Tuple for form choices and test which character has been selected:
    for x in range(len(charId_list)):            
        i = GetProfile_res['Response']['profile']['data']['characterIds'][x]
        # Populate drop down menu:
        race_name       = get_definition('DestinyRaceDefinition', (GetProfile_res['Response']['characters']['data'][i]['raceHash']))
        gender_name     = get_definition('DestinyGenderDefinition', (GetProfile_res['Response']['characters']['data'][i]['genderHash']))
        destiny_class   = get_definition('DestinyClassDefinition', (GetProfile_res['Response']['characters']['data'][i]['classHash']))
        emblem_hash     = GetProfile_res['Response']['characters']['data'][i]['emblemHash']
        base_level      = GetProfile_res['Response']['characters']['data'][i]['baseCharacterLevel']
        light           = GetProfile_res['Response']['characters']['data'][i]['light']
        dateLastPlayed  = GetProfile_res['Response']['characters']['data'][i]['dateLastPlayed']
        titleRecordHash = GetProfile_res['Response']['characters']['data'][i].get('titleRecordHash', None)
        minutesPlayedThisSession    = GetProfile_res['Response']['characters']['data'][i]['minutesPlayedThisSession']
        minutesPlayedTotal          = GetProfile_res['Response']['characters']['data'][i]['minutesPlayedTotal']

        emblem = get_emblem(emblem_hash)
        title  = get_title(titleRecordHash) if titleRecordHash is not None else None
        temp_dict = {
            i: {
                "character_id"  : i,
                "race_name"     : race_name['displayProperties']['name'],
                "gender_name"   : gender_name['displayProperties']['name'],
                "destiny_class" : destiny_class['displayProperties']['name'],
                "emblem_hash"   : emblem,
                "base_level"    : base_level,
                "light"         : light,
                "title"         : title,
                "dateLastPlayed"            : dateLastPlayed,
                "minutesPlayedThisSession"  : minutesPlayedThisSession,
                "minutesPlayedTotal"        : minutesPlayedTotal,
            }
        }
        character_details.update(temp_dict)

    #json_logger(GetProfile_res, "GetProfile.json")
    # with open('xur_response_GetVendors_hash.json', 'w') as outfile:
    #     json.dump(res.json(), outfile, sort_keys=True, indent=4)

    return character_details
Exemplo n.º 2
0
def get_title(title_hash):
    """
    Get the higher resolution emblem.
    """
    title_full = get_definition('DestinyRecordDefinition', title_hash)

    # print(emblem_full)

    title_data ={
        "icon"  : title_full['displayProperties']['icon'],
        "name"  : title_full['displayProperties']['name'],
        "description": title_full['displayProperties']['description'],
        "title" : title_full['titleInfo']['titlesByGender']['Female'],
    }
    
    return title_data
Exemplo n.º 3
0
def get_emblem(emblem_hash):
    """
    Get the higher resolution emblem.
    """
    emblem_full = get_definition('DestinyInventoryItemDefinition', emblem_hash)

    # print(emblem_full)

    emblem_data ={
        "icon": emblem_full['secondaryOverlay'],
        "background": emblem_full['secondarySpecial'],
        "secondaryIcon": emblem_full['secondaryIcon'],
        "description": emblem_full['displayProperties']['description']
    }
    
    return emblem_data
Exemplo n.º 4
0
def get_manifest(definition, def_hash):

    def_list = MANIFEST_DEFINITIONS

    if definition in def_list and isinstance(def_hash, int):
        response = get_definition(str(definition), str(def_hash))
        # print(response)
    else:
        def_hash_manifest_item = Manifest.query.filter_by(
            definition_id=str(def_hash)).all()
        print("Definition not found!")
        print(def_hash)
        print(definition)
        print(type(def_hash))
        print(def_hash_manifest_item)
        response = {"Response": "Error"}

    return jsonify(response)
Exemplo n.º 5
0
    else:
        status = "No change"

    end_time = time.time() - start_time
    print("-I- Run time:", end_time, "seconds")

    message = message + f" Revision: {db_version.current_revision} \nDate: {db_version.update_date}"
    response = {
        'Status': status,
        'Message': message,
        'Run_time': end_time,
        'Time': time
    }
    return response


if __name__ == "__main__":
    print("\t-I- This is the main function.")
    run_get_json_manifest_full(force=True)
    my_def = get_definition("DestinyInventoryItemLiteDefinition", "1409726986")
    print(my_def.get('displayProperties', None))

    my_def = get_definition("DestinyInventoryItemDefinition", "347366834")
    print(my_def.get('displayProperties', None))

    my_def = get_definition("DestinyClassDefinition", "2271682572")
    print(my_def.get('displayProperties', None))

    my_def = get_definition("DestinyMilestoneDefinition", "1300394968")
    print(my_def.get('displayProperties', None))
Exemplo n.º 6
0
def pgcr_list(membershipType, membershipId, characterId):

    mode_arg = request.args.get('game_mode', 'pvp')

    game_mode_switch = {
        'pvp': 5,
        'trials': 84,
        'gambit': 63,
        'raid': 4,
        'nightfall': 46,
        'dungeon': 82,
    }
    game_mode = game_mode_switch[mode_arg]

    game_count = 10

    user = User.query.filter_by(
        bungieMembershipId=g.user.bungieMembershipId).first()
    my_api = BungieApi(user)

    activity = my_api.get_activity_history(membershipType,
                                           membershipId,
                                           characterId,
                                           mode=game_mode,
                                           count=game_count)

    pgcr_list = []
    stat_list = []
    activities_res = activity["Response"].get("activities", None)
    if not activities_res:
        print("\n\n\nNo activities!!!")
        pgcr_list_res = {
            "Response": stat_list,
            "statusCode": 200,
            "ErrorStatus": "Success",
        }

        return jsonify(pgcr_list_res)

    for a in activity["Response"]["activities"]:
        pgcr_list.append(a["activityDetails"]["instanceId"])
    pgcr_res_list = []

    for index, instanceId in enumerate(pgcr_list):
        pgcr_res = my_api.get_pgcr(instanceId)
        pgcr_res_list.append(pgcr_res["Response"])

        for entry in pgcr_res["Response"]["entries"]:
            if entry["player"]["destinyUserInfo"][
                    "membershipId"] == membershipId:
                try:
                    avg_life = int(entry["values"]["activityDurationSeconds"]
                                   ["basic"]["value"] /
                                   entry["values"]["deaths"]["basic"]["value"])
                except ZeroDivisionError:
                    avg_life = int(666)
                stats = {
                    "count":
                    index,
                    "instanceId":
                    pgcr_res["Response"]["activityDetails"]["instanceId"],
                    "PGCR":
                    pgcr_res["Response"]["activityDetails"]["instanceId"],
                    "period":
                    pgcr_res["Response"]["period"],
                    "standing":
                    entry["standing"],
                    "activityDurationSeconds":
                    entry["values"]["activityDurationSeconds"]["basic"]
                    ["displayValue"],
                    "averageLifeTime":
                    avg_life,
                    "precisionKills":
                    entry["extended"]["values"]["precisionKills"]["basic"]
                    ["displayValue"],
                    "data":
                    entry,
                }

                # Add weapon definition to responses:
                try:
                    for index, weapons in enumerate(
                            entry["extended"].get("weapons")):
                        definition = get_definition(
                            "DestinyInventoryItemDefinition",
                            str(weapons["referenceId"]))
                        stats["data"]["extended"]["weapons"][index][
                            "definition"] = definition
                except:
                    continue
                stat_list.append(stats)

    pgcr_list_res = {
        "Response": stat_list,
        "statusCode": 200,
        "ErrorStatus": "Success",
    }

    return jsonify(pgcr_list_res)