Skip to content

Commit 89f84bc

Browse files
committedDec 11, 2023
Use Quart for async handling effectively
1 parent f6c9104 commit 89f84bc

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed
 

‎__pycache__/app.cpython-310.pyc

5.64 KB
Binary file not shown.

‎app.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Flask, request, render_template, Response
1+
from quart import Quart, request, render_template
22
import hypersync
33
import asyncio
44
import pandas as pd
@@ -34,26 +34,26 @@
3434
"okbc_testnet": "https://okbc-testnet.hypersync.xyz"
3535
}
3636

37-
app = Flask(__name__)
37+
app = Quart(__name__)
3838

3939
@app.route('/', methods=['GET', 'POST'])
40-
def index():
40+
async def index():
4141
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']
4646
network_url = NETWORK_URLS.get(selected_network, "https://eth.hypersync.xyz")
4747
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)
4949
img = create_plot(directory, request_type)
5050
# 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)
5252
except Exception as e:
5353
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}")
5555

56-
return render_template('index.html')
56+
return await render_template('index.html')
5757

5858

5959
async def fetch_data(address, selected_network, network_url, request_type):

‎data/.DS_Store

-4 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.