__init__.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """Inwoner Residency en Locatie Tracker"""
  2. import os
  3. import logging
  4. from sqlalchemy import create_engine
  5. from sqlalchemy.orm import sessionmaker
  6. from dotenv import load_dotenv
  7. from apscheduler.schedulers.background import BackgroundScheduler
  8. from app.models import Base, State, Region, Player
  9. load_dotenv()
  10. # database
  11. ENGINE = create_engine(os.environ["DATABASE_URI"], client_encoding='utf8')
  12. SESSION = sessionmaker(bind=ENGINE)
  13. # scheduler
  14. SCHEDULER = BackgroundScheduler(
  15. daemon=True,
  16. job_defaults={'misfire_grace_time': 900},
  17. )
  18. SCHEDULER.start()
  19. # module logger
  20. LOGGER = logging.getLogger(__name__)
  21. LOGGER.setLevel(logging.INFO)
  22. SCHEDULER_LOGGER = logging.getLogger('apscheduler')
  23. SCHEDULER_LOGGER.setLevel(logging.DEBUG)
  24. # create file handler
  25. FILE_HANDLER = logging.FileHandler('irlt.log')
  26. FILE_HANDLER.setLevel(logging.DEBUG)
  27. # create console handler
  28. STREAM_HANDLER = logging.StreamHandler()
  29. STREAM_HANDLER.setLevel(logging.INFO)
  30. # create formatter and add it to the handlers
  31. FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  32. STREAM_HANDLER.setFormatter(FORMATTER)
  33. FILE_HANDLER.setFormatter(FORMATTER)
  34. # add the handlers to logger
  35. LOGGER.addHandler(STREAM_HANDLER)
  36. LOGGER.addHandler(FILE_HANDLER)
  37. SCHEDULER_LOGGER.addHandler(STREAM_HANDLER)
  38. SCHEDULER_LOGGER.addHandler(FILE_HANDLER)
  39. # api
  40. BASE_URL = os.environ["API_URL"]
  41. HEADERS = {
  42. 'Authorization': os.environ["AUTHORIZATION"]
  43. }