42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from datetime import datetime, timezone, timedelta
|
|
from flask import Flask
|
|
from app.config import Config
|
|
from app.db import init_db, close_db
|
|
|
|
SYDNEY_TZ = timezone(timedelta(hours=11))
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.config.from_object(Config)
|
|
|
|
# Database lifecycle
|
|
init_db(app)
|
|
app.teardown_appcontext(close_db)
|
|
|
|
# Jinja2 filter: convert UTC to Sydney time
|
|
@app.template_filter('sydney')
|
|
def sydney_time_filter(dt, fmt='%d %b %Y, %H:%M'):
|
|
if dt is None:
|
|
return ''
|
|
if dt.tzinfo is None:
|
|
dt = dt.replace(tzinfo=timezone.utc)
|
|
return dt.astimezone(SYDNEY_TZ).strftime(fmt)
|
|
|
|
# Register blueprints
|
|
from app.routes.auth import bp as auth_bp
|
|
from app.routes.dashboard import bp as dashboard_bp
|
|
from app.routes.checkin import bp as checkin_bp
|
|
from app.routes.profile import bp as profile_bp
|
|
from app.routes.leaderboard import bp as leaderboard_bp
|
|
from app.routes.api import bp as api_bp
|
|
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(dashboard_bp)
|
|
app.register_blueprint(checkin_bp)
|
|
app.register_blueprint(profile_bp)
|
|
app.register_blueprint(leaderboard_bp)
|
|
app.register_blueprint(api_bp)
|
|
|
|
return app
|