35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import os
|
|
from flask import Flask
|
|
from misc import currDay, datetime, time, timedelta
|
|
from db import db, Period, Event
|
|
from create_events import createEvents
|
|
from apscheduler.schedulers.background import BlockingScheduler
|
|
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
app = Flask(__name__)
|
|
app.config['SECRET_KEY'] = os.environ['SECRET_KEY']
|
|
app.config['SQLALCHEMY_DATABASE_URI'] =\
|
|
'mysql://' + os.environ['MYSQL_USER'] + \
|
|
':' + os.environ['MYSQL_PASSWORD'] + \
|
|
'@' + os.environ['MYSQL_HOST'] + \
|
|
':' + os.environ['MYSQL_PORT'] + \
|
|
'/' + os.environ['MYSQL_DB']
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
db.init_app(app)
|
|
|
|
# Define function to run create_events with app context
|
|
def run_create_events():
|
|
with app.app_context():
|
|
createEvents(db, currDay, Period, Event)
|
|
|
|
# Call createEvents on initial launch of the script
|
|
run_create_events()
|
|
|
|
|
|
# Set up scheduler to run function at 59th minute of every hour
|
|
scheduler = BlockingScheduler()
|
|
scheduler.add_job(run_create_events, 'cron', minute=59)
|
|
|
|
# Start scheduler
|
|
scheduler.start() |