I cannot work on more until I rewrite this garbage:
#๐ Help rewriting fastapi function
5 messages ยท Page 1 of 1 (latest)
@sly warren
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
key_validation = secrets.token_urlsafe(32)
user_id = int(data["user"]["id"])
# validated earlier
record = await app.state.db.fetchrow("SELECT * FROM VALIDATION_KEYS SELECT user_id = $1", user_id)
if not record:
await app.state.db.execute("INSERT INTO VALIDATION_KEYS VAULUES($1, $2)", user_id, key_validation)
# how do I make this encypted
response.set_cookie(key="validation_key", value=key_validation)
# re-use cookie I suppose?
# will need to be added to database as encypted.
# prevents people from downloading wrong data.
json_string = json.dumps(data, indent=4)
json_response = io.StringIO(json_string)
# also add support for the asqlite version in the future too.
with tempfile.NamedTemporaryFile(mode="w") as f:
# delete on close may be already used
# delete is necessary possibly but idk, I just know delete_on_close=True isn't in python 3.11
# is delete needed?
# appraently it's also autodeleted
# https://stackoverflow.com/questions/11043372/how-to-use-tempfile-namedtemporaryfile
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
# does f even work with it?
async with asqlite.connect(f.name) as conn:
async with conn.cursor() as cursor:
print(conn)
# unsure how to handle the json response right now will ask dpy for help for that.
# file support
# find out how to download the json and also to respond with the stats via html
# will be json response in a bit or not idk.
# html responses with download html attribute
# le pain.
html = """
<pre>
{ "nice": "stats" }
</pre>
<a href="download_link.json" download>Download as JSON</a>
<a href="download_link.sqlite" download>Download as SQLite</a>
"""
# suggested solution from python.
# write actual stats there soon
return HTMLResponse(content=html)
(this is garbage)
@sly warren
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.