Exemple #1
0
    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 anonymize_json(json_data, filename):
    # this method may be called with a filename that does not exist
    # so we want to create the file which is required for subsequent logic
    dump_json_to_file(json_data, filename)

    user_id = ""

    # battle/get_battle_init_data API
    if json_data.get('battle'):
        print "Anonymizing a battle/get_battle_init_data API response"
        user_id = json_data['battle']['buddy'][0]['ability_panels'][0]['uid']

    # dff/party/list
    if json_data.get('equipments') and json_data.get('materials'):
        print "Anonymizing a dff/party/list API response"
        user_id = str(json_data['party']['user_id'])

    # validate user_id before anonymizing
    if validate_user_id(user_id):
        anonymize_file(filename, user_id)