__init__.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. Website and API
  3. """
  4. import os
  5. from flask import Flask
  6. from flask_sqlalchemy import SQLAlchemy
  7. from flask_login import LoginManager
  8. from flask_migrate import Migrate
  9. from flask_argon2 import Argon2
  10. from dotenv import load_dotenv
  11. from sqlalchemy import MetaData
  12. from rival_regions_wrapper.rival_regions_wrapper import Client
  13. load_dotenv()
  14. # app
  15. class Config():
  16. """Config settings for the application"""
  17. SECRET_KEY = os.environ["SECRET_KEY"]
  18. SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URI"]
  19. SQLALCHEMY_TRACK_MODIFICATIONS = False
  20. SEND_FILE_MAX_AGE_DEFAULT = 1296000
  21. app = Flask(__name__)
  22. app.config.from_object(Config())
  23. app.jinja_env.lstrip_blocks = True
  24. app.jinja_env.trim_blocks = True
  25. # db
  26. convention = {
  27. "ix": 'ix_%(column_0_label)s',
  28. "uq": "uq_%(table_name)s_%(column_0_name)s",
  29. "ck": "ck_%(table_name)s_%(constraint_name)s",
  30. "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
  31. "pk": "pk_%(table_name)s"
  32. }
  33. metadata = MetaData(naming_convention=convention)
  34. db = SQLAlchemy(app, metadata=metadata)
  35. migrate = Migrate(app, db)
  36. # Login
  37. login_manager = LoginManager()
  38. login_manager.init_app(app)
  39. login_manager.login_view = "login"
  40. login_manager.login_message_category = "warning"
  41. argon2 = Argon2(app)
  42. # Rival Region wrapper
  43. rrclient = Client(show_window=os.environ["SHOW_WINDOW"] == 'True')
  44. rrclient.set_credentials({
  45. "login_method": os.environ["LOGIN_METHOD"],
  46. "username": os.environ["USERNAME"],
  47. "password": os.environ["PASSWORD"]
  48. })
  49. alt_rrclient = Client(show_window=os.environ["ALT_SHOW_WINDOW"] == 'True')
  50. alt_rrclient.set_credentials({
  51. "login_method": os.environ["ALT_LOGIN_METHOD"],
  52. "username": os.environ["ALT_USERNAME"],
  53. "password": os.environ["ALT_PASSWORD"]
  54. })