def no_cache_api(request): api_key = os.getenv('HALOPY_API_KEY', False) if api_key: hpy = HaloPy(api_key, cache_backend='memory') hpy.cache = 0 hpy.rate = (1, 2) return hpy raise ValueError('No API key defined')
def api(request): def finalize(): time.sleep(2) request.addfinalizer(finalize) api_key = os.getenv('HALOPY_API_KEY', False) if api_key: return HaloPy(api_key, cache_backend='memory') raise ValueError('No API key defined')
from flask import Flask, jsonify, redirect, request, render_template, url_for from halopy import HaloPy import sys, http.client, urllib.request, urllib.parse, urllib.error, base64, json HALO_API_KEY = "03b04056ea114947beaa40503aba4a55" app = Flask(__name__) halo = HaloPy(HALO_API_KEY, cache_backend='memory') def get_latest_match_id(): return "23c056aa-c05e-4ae7-99ae-d4a282e4530a" def count_all_kills(): kill_data = {} params = urllib.parse.urlencode({}) match_id = get_latest_match_id() path = "/stats/h5/matches/" + match_id + "/events?" + params data = call_api(path) kill_data["gunkills"] = count_kills(data, "IsWeapon") kill_data["meleekills"] = count_kills(data, "IsMelee") kill_data["assassinations"] = count_kills(data, "IsAssassination") kill_data["groundpounds"] = count_kills(data, "IsGroundPound") kill_data["shoulderbash"] = count_kills(data, "IsShoulderBash") kill_data["headshots"] = count_kills(data, "IsHeadshot") kill_data["total"] = count_kills(data) return kill_data
def test_bad_request(): hpy = HaloPy(None, cache=0, cache_backend='memory') with pytest.raises(Exception) as ex: for x in range(10): hpy.get_campaign_missions()