def handle_response(self, flow): # we only care about URLs that are going to FFRK_HOST if FFRK_HOST in flow.request.host: # get_battle_init_data call if BATTLE_INFO_PATH in flow.request.path: print flow.request.path + " called" with decoded(flow.response): json_data = json.loads(flow.response.content) print get_drops_from_json(json_data) if DUMP_CONTENT_TO_FILES: dump_json_to_file(json_data, BATTLE_INFO_FILENAME + get_suffix_with_unix_time()) # dff/party/list call elif EQUIPMENT_LIST_PATH in flow.request.path: print flow.request.path + " called" with decoded(flow.response): json_data = json.loads(flow.response.content) print get_equipment_id_from_json(json_data) if DUMP_CONTENT_TO_FILES: dump_json_to_file(json_data, EQUIPMENT_LIST_FILENAME + get_suffix_with_unix_time()) else: print flow.request.path + " called; no processing done\n" # forward the reply so it gets passed on flow.reply()
def test_battle_drop_parser(): with open("json/get_battle_init_data-1430543134.json") as data_file: result = get_drops_from_json(json.load(data_file)) assert "White Orb" in result and "Round 1" in result with open("json/get_battle_init_data-1430542137.json") as data_file: result = get_drops_from_json(json.load(data_file)) assert "Twist Headband (V)" in result and "Round 1" in result assert "Minor White Orb" in result and "Round 2" in result