__init__.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. """Hervul en Voorspel Systeem"""
  2. import os
  3. import logging
  4. import telegram
  5. from sqlalchemy import create_engine
  6. from sqlalchemy.orm import sessionmaker
  7. from dotenv import load_dotenv
  8. from apscheduler.schedulers.background import BackgroundScheduler
  9. from app.models import Base, Region, DeepExploration, ResourceTrack, ResourceStat
  10. load_dotenv()
  11. # Telegram
  12. TELEGRAM_BOT = telegram.Bot(os.environ['TELEGRAM_KEY'])
  13. # database
  14. ENGINE = create_engine(os.environ["DATABASE_URI"])
  15. SESSION = sessionmaker(bind=ENGINE)
  16. # scheduler
  17. SCHEDULER = BackgroundScheduler(
  18. daemon=True,
  19. job_defaults={'misfire_grace_time': 300},
  20. )
  21. SCHEDULER.start()
  22. # get logger
  23. LOGGER = logging.getLogger(__name__)
  24. LOGGER.setLevel(logging.INFO)
  25. SCHEDULER_LOGGER = logging.getLogger('apscheduler')
  26. SCHEDULER_LOGGER.setLevel(logging.DEBUG)
  27. # create file handler
  28. FILE_HANDLER = logging.FileHandler('output.log')
  29. FILE_HANDLER.setLevel(logging.DEBUG)
  30. # create console handler
  31. STREAM_HANDLER = logging.StreamHandler()
  32. STREAM_HANDLER.setLevel(logging.INFO)
  33. # create formatter and add it to the handlers
  34. FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  35. STREAM_HANDLER.setFormatter(FORMATTER)
  36. FILE_HANDLER.setFormatter(FORMATTER)
  37. # add the handlers to logger
  38. LOGGER.addHandler(STREAM_HANDLER)
  39. LOGGER.addHandler(FILE_HANDLER)
  40. SCHEDULER_LOGGER.addHandler(STREAM_HANDLER)
  41. SCHEDULER_LOGGER.addHandler(FILE_HANDLER)
  42. # api
  43. BASE_URL = os.environ["API_URL"]
  44. HEADERS = {
  45. 'Authorization': os.environ["AUTHORIZATION"]
  46. }
  47. RESOURCE_IDS = {
  48. 0: 'gold',
  49. 3: 'oil',
  50. 4: 'ore',
  51. 11: 'uranium',
  52. 15: 'diamond',
  53. }
  54. RESOURCE_NAMES = {
  55. 'gold': 0,
  56. 'oil': 3,
  57. 'ore': 4,
  58. 'uranium': 11,
  59. 'diamond': 15,
  60. }
  61. RESOURCE_MAX = {
  62. 0: 2500,
  63. 3: 600,
  64. 4: 500,
  65. 11: 60,
  66. 15: 75,
  67. }