-
Notifications
You must be signed in to change notification settings - Fork 33
/
utils.py
32 lines (26 loc) · 1.21 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
import logging
import os
from pyeslogging.handlers import PYESHandler
from telegram import Bot
from telegram.utils.request import Request
def get_logger():
# Enable logging
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
if os.getenv('ELASTIC_HOST') and os.getenv('ELASTIC_USER') and os.getenv('ELASTIC_PASS') and \
os.getenv('SEND_LOGS_TO_ELASTIC'):
handler = PYESHandler(hosts=[{'host': os.getenv('ELASTIC_HOST'), 'port': 9200}],
auth_type=PYESHandler.AuthType.BASIC_AUTH,
auth_details=(os.getenv('ELASTIC_USER'), os.getenv('ELASTIC_PASS')),
es_index_name="munich-tg-logs",
index_name_frequency=PYESHandler.IndexNameFrequency.MONTHLY)
logger.addHandler(handler)
return logger
def get_bot():
# Default size from the library, 4 workers + 4 additional
request = Request(con_pool_size=8)
return Bot(token=os.getenv("TG_TOKEN"), request=request)
def get_min_interval():
return int(os.getenv("MIN_CHECK_INTERVAL_MINUTES", 15))