Esempio n. 1
0
def get_characters():
    user = User.query.filter_by(
        bungieMembershipId=g.user.bungieMembershipId).first()
    my_api = BungieApi(user)

    get_account_res = my_api.GetCurrentBungieAccount()

    # Take values from request args- or default to stored values:
    membershipId = str(
        request.args.get(
            'membershipId',
            str(get_account_res["Response"]["destinyMemberships"][0]
                ["membershipId"])))
    membershipType = str(
        request.args.get(
            'membershipType',
            str(get_account_res["Response"]["destinyMemberships"][0]
                ["membershipType"])))

    get_characters_res = my_api.get_profile(membershipType, membershipId)

    if get_characters_res["ErrorStatus"] != "Success":
        flash(
            f"Bungies systems are down: {get_characters_res.get('message', {}).get('Message', {})}",
            "error")
        return redirect(url_for("public.home"))

    character_details = get_character_details_json(get_characters_res)

    return jsonify(character_details)
Esempio n. 2
0
def get_profile():
    user = User.query.filter_by(
        bungieMembershipId=g.user.bungieMembershipId).first()
    my_api = BungieApi(user)

    # TODO: Hardcoded values:
    # Take values from here: GetCurrentBungieAccount
    get_account_res = my_api.GetCurrentBungieAccount()

    membershipId = int(
        request.args.get(
            'membershipId',
            str(get_account_res["Response"]["destinyMemberships"][0]
                ["membershipId"])))
    membershipType = int(
        request.args.get(
            'membershipType',
            str(get_account_res["Response"]["destinyMemberships"][0]
                ["membershipType"])))

    # print(type(get_account_res))
    # print(get_account_res.json())
    membershipId = str(
        get_account_res["Response"]["destinyMemberships"][0]["membershipId"])
    membershipType = str(
        get_account_res["Response"]["destinyMemberships"][0]["membershipType"])
    get_profile_res = my_api.get_profile(membershipType, membershipId)

    return jsonify(get_profile_res)
Esempio n. 3
0
def gambit(membershipType, membershipId, characterId):
    user = User.query.filter_by(
        bungieMembershipId=g.user.bungieMembershipId).first()
    my_api = BungieApi(user)

    get_profile_res = my_api.get_profile(membershipType, membershipId)
    if get_profile_res["ErrorStatus"] != "Success":
        flash("Bungies systems are down :(", "error")
        return redirect(url_for("public.home"))

    return render_template("auth/choose_focus.html")
Esempio n. 4
0
def get_gambit(membershipType, membershipId, characterId):
    user = User.query.filter_by(
        bungieMembershipId=g.user.bungieMembershipId).first()
    my_api = BungieApi(user)
    get_profile_res = my_api.get_profile(membershipType, membershipId)

    activity = my_api.get_activity_history(membershipType,
                                           membershipId,
                                           characterId,
                                           mode=63,
                                           count=30)

    return jsonify(activity)
Esempio n. 5
0
def pvp(membershipType, membershipId, characterId):
    user = User.query.filter_by(
        bungieMembershipId=g.user.bungieMembershipId).first()
    my_api = BungieApi(user)

    get_profile_res = my_api.get_profile(membershipType, membershipId)
    if get_profile_res["ErrorStatus"] != "Success":
        flash(
            f"Bungies systems are down: {get_profile_res.get('message', {}).get('Message', {})}",
            "error")

        return redirect(url_for("public.home"))

    # character_details = get_character_details_json(get_profile_res)

    return render_template("auth/choose_focus.html")
Esempio n. 6
0
def get_historical_stats_alltime(membershipType, membershipId, characterId):
    user = User.query.filter_by(
        bungieMembershipId=g.user.bungieMembershipId).first()
    my_api = BungieApi(user)

    get_profile_res = my_api.get_profile(membershipType, membershipId)
    character_details = get_character_details_json(get_profile_res)

    activity = my_api.get_historical_stats(membershipType,
                                           membershipId,
                                           characterId,
                                           daystart="",
                                           dayend="")

    # if daystart < new_date:
    #     print("daystart < new_date")
    print("Testing time delta:")

    return jsonify(activity)
Esempio n. 7
0
def oauth_callback(provider):
    """ Callback URL for a given provider."""
    # flash("You are in the callback URL.", "info")

    # Get token from Bungie:
    oauth = OAuthSignin(provider).get_provider(provider)
    token_response = oauth.get_callback_url()
    print(token_response)

    # Handle CSRF error:
    if token_response is False:
        return render_template("401.html")

    if 'access_token' not in token_response.json():
        # print(token_response)
        # print(token_response.content)
        # print(token_response.json())
        return render_template("401.html")

    auth_headers = {}
    token_json = token_response.json()['access_token']
    membership_id = token_response.json()["membership_id"]
    auth_headers["X-API-Key"] = OAuthSignin(provider).api_key
    auth_headers["Authorization"] = 'Bearer ' + str(token_json)
    auth_headers["membership_id"] = str(membership_id)

    # Create and authorized session for making requests:
    auth_session = requests.Session()
    auth_session.headers = {
        "X-API-Key": auth_headers['X-API-Key'],
        'Authorization': auth_headers['Authorization']
    }

    # Get Bungie Profile:
    #  This gives membership type - which is needed for all subsequent calls.
    get_user_url = "https://www.bungie.net/Platform/User/" + "GetCurrentBungieAccount/"
    get_account_res = auth_session.get(get_user_url)

    user = User.query.filter_by(bungieMembershipId=membership_id).first()
    # print(user)
    # print(get_account_res.json()['Response'])
    if user is None:
        user = create_user(get_account_res.json(), token_response.json())
    else:
        print("Welcome back user.")
        user = update_user(user=user,
                           get_account_res=get_account_res.json(),
                           token_response=token_response.json())

    login_user(user)

    # flash("You are logged in.", "success")

    # Return the raw JSON content:
    # return jsonify(get_account_res.json())

    membershipId = get_account_res.json(
    )["Response"]["destinyMemberships"][0]["membershipId"]
    membershipType = get_account_res.json(
    )["Response"]["destinyMemberships"][0]["membershipType"]

    my_api = BungieApi(user)
    get_profile_res = my_api.get_profile(str(membershipType),
                                         str(membershipId))
    characterId = get_profile_res["Response"]["profile"]["data"][
        "characterIds"][0]

    # TODO:
    # Redirect to get_profile - > Get: membershipType destinyMembershipId
    # Redirect to chose_track/membershipType/destinyMembershipId.

    return redirect(
        url_for("auth.choose_focus",
                membershipType=membershipType,
                membershipId=membershipId,
                characterId=characterId))