T
T
Tayrus02021-11-21 21:13:46
Python
Tayrus0, 2021-11-21 21:13:46

How to make given code asynchronous in flask?

Is there such a code how to make it asynchronous? That is, so that when one user has the check() function executed, and the other, it also starts to be executed? You can use another framework, I don't know which one is better.

js_stub = open("_.js", "r", encoding='utf-8').read()
process = frida.get_usb_device(1).attach('valhala')
results_pool = {}

app = Flask(__name__)


def on_message(message):
    payload = message['payload']
    splitted = payload.split('|')

    uid = splitted[0]
    response = splitted[1]

    results_pool[uid] = response


def get_script(numbers_json, uid):
    return js_stub.replace('{uid}', uid).replace('{numbers}', numbers_json)


def get_result(uid):
    while True:
        if uid in results_pool:
            break

    return results_pool[uid]


@app.route('/check')
def check():
    number = '+' + request.args.get('number')
    numbers = [number]

    uid = hashlib.md5((number + str(time.time())).encode('utf-8')).hexdigest()

    js_script = get_script(json.dumps(numbers), uid)
    frida_script = process.create_script(js_script)
    frida_script.on('message', on_message)

    frida_script.load()

    result = get_result(uid)

    users_details = json.loads(result)['UsersDetails']
    is_get = bool(users_details[0]['MID'] != '')
    return jsonify(
        exists=is_get
    )


if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0', use_reloader=False)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-11-22
@twistfire92

If you want asynchrony, look towards FastApi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question