__init__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """STate Region Logger"""
  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. load_dotenv()
  9. # database
  10. ENGINE = create_engine(os.environ["DATABASE_URI"], client_encoding='utf8')
  11. SESSION = sessionmaker(bind=ENGINE)
  12. # scheduler
  13. SCHEDULER = BackgroundScheduler(
  14. daemon=True,
  15. job_defaults={'misfire_grace_time': 10*60},
  16. )
  17. SCHEDULER.start()
  18. # get logger
  19. LOGGER = logging.getLogger(__name__)
  20. LOGGER.setLevel(logging.INFO)
  21. SCHEDULER_LOGGER = logging.getLogger('apscheduler')
  22. SCHEDULER_LOGGER.setLevel(logging.DEBUG)
  23. # create file handler
  24. FILE_HANDLER = logging.FileHandler('output.log')
  25. FILE_HANDLER.setLevel(logging.DEBUG)
  26. # create console handler
  27. STREAM_HANDLER = logging.StreamHandler()
  28. STREAM_HANDLER.setLevel(logging.INFO)
  29. # create formatter and add it to the handlers
  30. FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  31. STREAM_HANDLER.setFormatter(FORMATTER)
  32. FILE_HANDLER.setFormatter(FORMATTER)
  33. # add the handlers to logger
  34. LOGGER.addHandler(STREAM_HANDLER)
  35. LOGGER.addHandler(FILE_HANDLER)
  36. SCHEDULER_LOGGER.addHandler(STREAM_HANDLER)
  37. SCHEDULER_LOGGER.addHandler(FILE_HANDLER)
  38. # api
  39. BASE_URL = os.environ["API_URL"]
  40. HEADERS = {
  41. 'Authorization': os.environ["AUTHORIZATION"]
  42. }