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)
def get_historical_stats(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) # TODO: Hardcoded AllPvP mode # season = 1 mode = int(request.args.get('game_mode', 5)) season = int(request.args.get('season', CURRENT_SEASON)) activity_list = [] season_start = datetime.strptime(SEASONS[season]['START'], "%Y-%m-%d %H:%M:%S") season_end = datetime.strptime(SEASONS[season]['END'], "%Y-%m-%d %H:%M:%S") month = 30 # month = 5 # Testing flow: current_date = datetime.utcnow() if season_end > current_date: day_end = current_date else: day_end = season_end day_start = day_end - timedelta(days=month) # print("Dates:") # print(day_start) # print(day_end) activity_list = [] while True: if day_start < season_start: # Last request: day_start = season_start activity = my_api.get_historical_stats(membershipType, membershipId, characterId, modes=mode, daystart=day_start, dayend=day_end, periodType='Daily') found_activities = activity.get('Response', {}).get('allPvP', {}).get('daily', False) if found_activities: for a in activity['Response']['allPvP']['daily']: activity_list.append(a) break else: activity = my_api.get_historical_stats(membershipType, membershipId, characterId, modes=mode, daystart=day_start, dayend=day_end, periodType='Daily') if activity["ErrorStatus"] != "Success": flash( f"Bungies systems are down: {activity.get('message', {}).get('Message', {})}", "error") return redirect(url_for("public.home")) found_activities = activity['Response']['allPvP'].get( 'daily', False) if found_activities: for a in activity['Response']['allPvP']['daily']: activity_list.append(a) day_end = day_start - timedelta(seconds=1) day_start = day_start - timedelta(days=month) summarised_activity = summarize_historical_stats(activity_list) new_activity = { "Response": { 'season': season, 'mode': ACTIVITY_MODES[mode], 'allPvP': { 'daily': summarised_activity } } } return jsonify(new_activity)