-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (58 loc) · 1.92 KB
/
main.py
File metadata and controls
82 lines (58 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import aiosqlite
import logging as logger # Don't remember why I did this
from quart import Quart
from dotenv import load_dotenv
from src.config import Config
from src.updater import DataUpdater
from src.routes.api_routes import api_blueprint
from src.routes.website_routes import website_blueprint
app = Quart(__name__)
def main() -> None:
# TODO: Ensure file structure exists before proceeding
# TODO: Ensure dotenv vars are working correctly
# TODO: Ensure config is okay
logger.basicConfig(level=logger.DEBUG)
load_dotenv()
app.register_blueprint(api_blueprint)
app.register_blueprint(website_blueprint)
key = os.getenv("key")
db_path = os.getenv("dbpath")
guild_id = os.getenv("guildid")
updater = DataUpdater(key, db_path, guild_id)
updater._run_update()
# app.run(debug=True, host='0.0.0.0', port=5000)
@app.before_serving
async def before_serving():
db_path = os.getenv("DB_PATH")
logger.debug(f"Opening connection to database at {db_path}...")
try:
app.db = await aiosqlite.connect(db_path)
logger.debug("Connection established")
except Exception as e:
logger.critical("Could not establish connection with database", e)
exit(12)
@app.after_serving
async def after_serving():
logger.debug("Closing database connection...")
await app.db.close()
logger.debug("Database connection closed")
if __name__ == "__main__":
main()
# Quart Example
# from dataclasses import dataclass
# from datetime import datetime
# from quart_schema import QuartSchema, validate_request, validate_response
# QuartSchema(app)
# @dataclass
# class TodoIn:
# task: str
# due: datetime | None
# @dataclass
# class Todoo(TodooIn):
# id: int
# @app.post("/todos/")
# @validate_request(TodooIn)
# @validate_response(Todoo)
# async def create_todo(data: Todoo) -> Todoo:
# return Todoo(id=1, task=data.task, due=data.due)