|
|
- from flask import Flask, g, request, session, redirect, url_for, render_template
- from flask_bootstrap import Bootstrap
- import yaml
- import datetime as dt
- import pytz
-
- app = Flask(__name__)
- Bootstrap(app)
- app.secret_key = 'asdf'
- app.debug = True
-
- eastern = pytz.timezone('US/Eastern')
-
- with open('config/config.yaml') as f:
- yaml_data = yaml.load(f, Loader=yaml.SafeLoader)
-
- search = yaml_data['search']
- account_url = yaml_data['accounts']['account_url']
-
- description = yaml_data['description']
-
- countdown_data = None
- if yaml_data['countdown']['active'] == True:
- countdown_data = yaml_data['countdown']
- print(countdown_data)
-
- final_countdown_data = None
- final_time = None
- if yaml_data['final_countdown']['active'] == True:
- final_countdown_data = yaml_data['final_countdown']
- final_time = eastern.localize(dt.datetime.strptime(final_countdown_data['timestamp'], '%B %d %Y %H:%M:%S%z').replace(tzinfo=None))
- print(final_countdown_data)
-
- apps = []
- for itm in yaml_data['apps'].items():
- apps.append(itm[1])
-
-
- @app.route('/')
- def index():
- current_time = eastern.localize(dt.datetime.now())
- if final_countdown_data != None:
- if (final_time - current_time).days > -1:
- return render_template('final_countdown.j2', final_countdown = final_countdown_data)
- if countdown_data != None:
- return render_template('index.j2', apps = apps, search = search, account_url = account_url, description = description, countdown = countdown_data)
- return render_template('index.j2', apps = apps, search = search, account_url = account_url, description = description)
-
-
- if __name__ == '__main__':
- app.run(extra_files="config/config.yaml")
|