You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. from flask import Flask, g, request, session, redirect, url_for, render_template
  2. from flask_bootstrap import Bootstrap
  3. import yaml
  4. import datetime as dt
  5. import pytz
  6. app = Flask(__name__)
  7. Bootstrap(app)
  8. app.secret_key = 'asdf'
  9. app.debug = True
  10. eastern = pytz.timezone('US/Eastern')
  11. with open('config/config.yaml') as f:
  12. yaml_data = yaml.load(f, Loader=yaml.SafeLoader)
  13. search = yaml_data['search']
  14. account_url = yaml_data['accounts']['account_url']
  15. description = yaml_data['description']
  16. countdown_data = None
  17. if yaml_data['countdown']['active'] == True:
  18. countdown_data = yaml_data['countdown']
  19. print(countdown_data)
  20. final_countdown_data = None
  21. final_time = None
  22. if yaml_data['final_countdown']['active'] == True:
  23. final_countdown_data = yaml_data['final_countdown']
  24. final_time = eastern.localize(dt.datetime.strptime(final_countdown_data['timestamp'], '%B %d %Y %H:%M:%S%z').replace(tzinfo=None))
  25. print(final_countdown_data)
  26. apps = []
  27. for itm in yaml_data['apps'].items():
  28. apps.append(itm[1])
  29. @app.route('/')
  30. def index():
  31. current_time = eastern.localize(dt.datetime.now())
  32. if final_countdown_data != None:
  33. if (final_time - current_time).days > -1:
  34. return render_template('final_countdown.j2', final_countdown = final_countdown_data)
  35. if countdown_data != None:
  36. return render_template('index.j2', apps = apps, search = search, account_url = account_url, description = description, countdown = countdown_data)
  37. return render_template('index.j2', apps = apps, search = search, account_url = account_url, description = description)
  38. if __name__ == '__main__':
  39. app.run(extra_files="config/config.yaml")