-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (59 loc) · 2.39 KB
/
main.py
File metadata and controls
71 lines (59 loc) · 2.39 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
from fastapi import Depends, FastAPI, Request
from fastapi.staticfiles import StaticFiles
from sqlalchemy.orm import Session
from app.config import PSQL_ENVIRONMENT
from app.database import models
from app.database.database import engine, get_db
from app.dependencies import (
MEDIA_PATH, STATIC_PATH, templates)
from app.internal.quotes import load_quotes, daily_quotes
from app.routers import (
agenda, dayview, email, event, invitation, profile, search, telegram,
keyboard_shortcuts, whatsapp)
from app.telegram.bot import telegram_bot
from app.internal.logger_customizer import LoggerCustomizer
from app import config
def create_tables(engine, psql_environment):
if 'sqlite' in str(engine.url) and psql_environment:
raise models.PSQLEnvironmentError(
"You're trying to use PSQL features on SQLite env.\n"
"Please set app.config.PSQL_ENVIRONMENT to False "
"and run the app again."
)
else:
models.Base.metadata.create_all(bind=engine)
create_tables(engine, PSQL_ENVIRONMENT)
app = FastAPI()
app.mount("/static", StaticFiles(directory=STATIC_PATH), name="static")
app.mount("/media", StaticFiles(directory=MEDIA_PATH), name="media")
load_quotes.load_daily_quotes(next(get_db()))
# Configure logger
logger = LoggerCustomizer.make_logger(config.LOG_PATH,
config.LOG_FILENAME,
config.LOG_LEVEL,
config.LOG_ROTATION_INTERVAL,
config.LOG_RETENTION_INTERVAL,
config.LOG_FORMAT)
app.logger = logger
app.include_router(profile.router)
app.include_router(event.router)
app.include_router(agenda.router)
app.include_router(telegram.router)
app.include_router(dayview.router)
app.include_router(email.router)
app.include_router(invitation.router)
app.include_router(whatsapp.router)
app.include_router(search.router)
app.include_router(keyboard_shortcuts.router)
telegram_bot.set_webhook()
# TODO: I add the quote day to the home page
# until the relavent calendar view will be developed.
@app.get("/")
@app.logger.catch()
async def home(request: Request, db: Session = Depends(get_db)):
quote = daily_quotes.quote_per_day(db)
return templates.TemplateResponse("home.html", {
"request": request,
"message": "Hello, World!",
"quote": quote
})