def main(): logger = LoggerInit.init_logging(config.log_file) logger.info('Application started') QueueWrapper.init() bot = Telegram(config.api_key) UserManager.init(bot) User.init() QueueWrapper.start(detach=True) try: for _ in bot.get_updates(): pass while True: logger.debug("Getting updates") for query in bot.get_updates(timeout=30): logger.debug(f'==> {query}') query_type = query['type'] body = query['body'] user_id = query['uid'] user = UserManager.get_or_create_user(user_id) if query_type == 'message': logger.debug("Sending message to user {}".format(user_id)) user.process_message(body) elif query_type == 'inline_req': logger.debug("Sending inline request to user {}".format(user_id)) user.process_inline_req(body) elif query_type == 'inline_ans': logger.debug("Sending inline answer to user {}".format(user_id)) user.process_inline_ans(body) elif query_type == 'callback': logger.debug("Sending callback to user {}".format(user_id)) user.process_callback(body) except KeyboardInterrupt: logger.debug('QueueWrapper.close') QueueWrapper.close()
def main(): LoggerInit.init_logging(config.log_update_manager_file) QueueWrapper.init() UpdatesManager.init_manager() QueueWrapper.start(detach=True) try: UpdatesManager.worker() except KeyboardInterrupt: QueueWrapper.close()
def main(): QueueWrapper.init() ProducerFactory.subscribe_producer(config.check_url_req_queue, config.check_url_ans_queue, check_url_callback) ProducerFactory.subscribe_producer(config.parse_url_req_queue, config.parse_url_ans_queue, parse_url_callback) ProducerFactory.subscribe_producer(config.parse_all_moscow_req_queue, config.parse_all_moscow_ans_queue, parse_url_callback) try: QueueWrapper.start(detach=False) except KeyboardInterrupt: QueueWrapper.close()
def main(): QueueWrapper.init() GlobalParser.register() SuspiciousChecker.register() QueueWrapper.start(detach=True) try: while True: time.sleep(60 * 60 * 60) except KeyboardInterrupt: GlobalParser.close_thread() SuspiciousChecker.close_thread() QueueWrapper.close()
import LoggerInit import config import pytz from datetime import datetime import time import logging from GlobalManager.GlobalParser import GlobalParser from GlobalManager.SuspiciousChecker import SuspiciousChecker from Queues import QueueWrapper from Queues.ProducerConsumer.ConsumerFactory import ConsumerFactory LoggerInit.init_logging(config.log_all_moscow_file) logger = logging.getLogger("AllMoscowParser") if __name__ == "__main__": QueueWrapper.init() GlobalParser.register() SuspiciousChecker.register() QueueWrapper.start(detach=True) try: while True: time.sleep(60 * 60 * 60) except KeyboardInterrupt: GlobalParser.close_thread() SuspiciousChecker.close_thread() QueueWrapper.close()