def __init__(self, bot, chat_id): """ :type bot: telegram.Bot :type chat_id: int """ self.bot = bot self.__chat_id = chat_id self.__log = get_logger(self.__class__.__name__)
def trigger_howarewe(token): global log checked_load_logging_config(CONFIG_PATH) log = get_logger(__name__) if not token: log.error('usage: %s=<token> python %s' % (BOT_TOKEN, os.path.basename(__file__))) sys.exit(255) log.info('starting %s' % __name__) updater = Updater(token) writer = TelegramWriter(updater.bot, MUC_TELEGRAM_GROUP_ID) WelfareCommandAction().callback_function(writer)
def _startup_bot(token): global log checked_load_logging_config(CONFIG_PATH) log = get_logger(__name__) if not token: log.error('usage: %s=<token> python %s' % (BOT_TOKEN, os.path.basename(__file__))) sys.exit(255) log.info('starting %s' % __name__) updater = Updater(token) BotRegistry(updater).register_commands() updater.start_polling() updater.idle() log.info('finished polling')
# coding: utf-8 from bottle import route, run from my_math import careful_division from my_logging import get_logger logger = get_logger(__name__) def danger(top, bottom): return { 'result': careful_division(top, bottom), 'error': None, } if __name__ == '__main__': for x in range(1, 5, 2): for y in range(-4, 2, 4): if x == 0 or y == 0: logger.info('Кто-то пытается делить на ноль!') print(danger(x, y))
# coding: utf-8 from bottle import request, route, run from my_logging import get_logger logger = get_logger("divider-server") @route("/<top:int>/<bottom:int>") def danger(top, bottom): res = {"result": 0, "error": None} try: res["result"] = top / bottom except ZeroDivisionError as error: res["error"] = f"Для входных данных {top} и {bottom} не получилось: {error}" agent = request.headers["User-Agent"] host = request.headers["Host"] path = request.path logger.error( f"Ошибка деления при обращении к {host}{path}. User-Agent: {agent}" ) return res if __name__ == "__main__": run(host="localhost", port=8080)
from bottle import request, route, run, view from datetime import datetime from random import random from horoscope import generate_prophecies from my_logging import get_logger logger = get_logger('divider-server') def tell_me_your_secret(): return 42 @route('/<top:int>/<bottom:int>') def danger(top, bottom): res = {'result': 0, 'error': None} try: res['result'] = top / bottom except ZeroDivisionError as zd: res['error'] = f'Для входных данных {top} и {bottom} не получилось {zd}' agent = request.headers["User-Agent"] host = request.headers["Host"] path = request.path logger.error( f"Ошибка деления при обращении к {host}{path}. User-Agent: {agent}" ) return res # def danger(top, bottom): # return {
# coding: utf-8 import logging from my_logging import get_logger logging = get_logger(logger_name=__name__, level=logging.DEBUG) def careful_division(x, y): logging.debug(f"Получены аргументы {x} and {y}") if y == 0 or x == 0: return 0 else: return x / y
# coding=utf-8 import os import requests from config import PIPEDRIVE_API_TOKEN, PIPEDRIVE_FILTER_ID, PIPEDRIVE_PIPLINE_ID, PIPEDRIVE_URL, \ PIPEDRIVE_COUNT_STAGES_FILTER, PIPEDRIVE_VALUE_STAGES_FILTER, TEAM_MATES_COUNT, PIPEDRIVE_MIN_DEALS_PER_MATE, \ PIPEDRIVE_MIN_EUROS_PER_MATE from my_logging import get_logger, checked_load_logging_config log = get_logger(__name__) PIPEDRIVE_REQUEST_API_TOKEN = '&api_token=' + os.getenv( PIPEDRIVE_API_TOKEN, '') def ask_pipedrive(): global log stages = get_stages() value_sum = 0 deal_count = 0 for stage in stages: if stage['name'] in PIPEDRIVE_VALUE_STAGES_FILTER: value_sum += sum_of_deal_values(stage) if stage['name'] in PIPEDRIVE_COUNT_STAGES_FILTER: deal_count += len(get_deals(stage['id'])) return get_interpretation(deal_count, value_sum)
# coding: utf-8 from bottle import route, run from my_math import careful_division from my_logging import get_logger logger = get_logger(logger_name=__name__) def danger(top, bottom): return { "result": careful_division(top, bottom), "error": None, } if __name__ == "__main__": for x in range(1, 5, 2): for y in range(-4, 2, 4): if y == 0 or x == 0: logger.info("Кто-то пытается делить на ноль!") print(danger(x, y))
#!/usr/bin/python import optparse import SimpleHTTPServer import SocketServer import urlparse import time import random import my_logging logger = my_logging.get_logger('mup', _logger_file='mup_http_server.log') URL = "http://10.64.41.155:8000" class MyHttpHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): TYPE = ('sugg_only', 'sugg_link', 'action_required', 'action_taken', 'attention_need', 'attention_need_max', 'problem_solved') STATUS = ('posted', 'action_taken', 'action_received', 'problem_solved', 'action_not_received', 'problem_not_solved') IMAGE_TYPE = ('protected', 'information', 'exclamation', 'risk') current_index = 0 def do_GET(self): logger.debug('receive a GET request') logger.debug('basic info >>>>>>>') client_info = self.get_client_basic_info() logger.debug(client_info) logger.debug('basic info <<<<<<<') time.sleep(3) self.send_response(200)
#!/usr/bin/python import SimpleHTTPServer import SocketServer import urlparse import time import my_logging logger = my_logging.get_logger('food', _logger_file='food_http_server.log') PORT = 8000 class MyHttpHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): logger.debug('receive a GET request') logger.debug('basic info >>>>>>>') client_info = self.get_client_basic_info() logger.debug(client_info) logger.debug('basic info <<<<<<<') time.sleep(3) self.send_response(200) self.end_headers() # self.wfile.write('''{"psid": 23974, "cnname": "\u6768\u5f6a", "name": "Salt Yang", "enname": "Salt Yang", "depcode": "CHT.5621E"}''') # self.wfile.write('''[{"orderid": "", "status": "p", "foodprice": 20, "delivery": "e", "foodname": "\u76d2\u996d"}]''') def do_POST(self): logger.debug('receive a POST request') logger.debug('basic info >>>>>>>')