|
1 |
| -from flask import Flask, request, render_template, Response |
| 1 | +from quart import Quart, request, render_template |
2 | 2 | import hypersync
|
3 | 3 | import asyncio
|
4 | 4 | import pandas as pd
|
|
34 | 34 | "okbc_testnet": "https://okbc-testnet.hypersync.xyz"
|
35 | 35 | }
|
36 | 36 |
|
37 |
| -app = Flask(__name__) |
| 37 | +app = Quart(__name__) |
38 | 38 |
|
39 | 39 | @app.route('/', methods=['GET', 'POST'])
|
40 |
| -def index(): |
| 40 | +async def index(): |
41 | 41 | if request.method == 'POST':
|
42 |
| - address = request.form['address'] |
43 |
| - address = address.lower() |
44 |
| - request_type = request.form['type'] |
45 |
| - selected_network = request.form['network'] |
| 42 | + form_data = await request.form # Await the form data |
| 43 | + address = form_data['address'].lower() |
| 44 | + request_type = form_data['type'] |
| 45 | + selected_network = form_data['network'] |
46 | 46 | network_url = NETWORK_URLS.get(selected_network, "https://eth.hypersync.xyz")
|
47 | 47 | try:
|
48 |
| - directory = asyncio.run(fetch_data(address, selected_network, network_url, request_type)) |
| 48 | + directory = await fetch_data(address, selected_network, network_url, request_type) |
49 | 49 | img = create_plot(directory, request_type)
|
50 | 50 | # img = 'data:image/png;base64,./assets/sad-pepe.png'
|
51 |
| - return render_template('plot.html', plot_url=img) |
| 51 | + return await render_template('plot.html', plot_url=img) |
52 | 52 | except Exception as e:
|
53 | 53 | print(f"Error: {e}")
|
54 |
| - return render_template('error.html', message="An unexpected error occurred.") |
| 54 | + return await render_template('error.html', message=f"An unexpected error occurred. Error: {e}") |
55 | 55 |
|
56 |
| - return render_template('index.html') |
| 56 | + return await render_template('index.html') |
57 | 57 |
|
58 | 58 |
|
59 | 59 | async def fetch_data(address, selected_network, network_url, request_type):
|
|
0 commit comments