<commit_before>#!/usr/bin/env python3

__author__ = 'm_messiah'
import logging
import signal
from requests import Session
import tornado.ioloop
import tornado.web
import tornado.escape
from os import environ as ENV

try:
    from bot_token import BOT_TOKEN
except:
    BOT_TOKEN = ENV["TOKEN"]
from commands import CMD


logging.basicConfig(level=logging.INFO)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.WARNING)


URL = "https://api.telegram.org/bot%s/" % BOT_TOKEN
MyURL = "https://messiah-bot.herokuapp.com"  # TODO: add url here, when get valid HTTPS

LAST_COMMAND = {}


def not_found(arguments, message):
    return {'chat_id': message['from']['id'],
            'text': "Command not found. Try /help"
            }

def send_reply(response):
    logging.debug("SENT\t%s" % response)
    if 'sticker' in response:
        api.post(URL + "sendSticker", data=response)
    elif 'text' in response:
        api.post(URL + "sendMessage", data=response)

# noinspection PyAbstractClass
class Handler(tornado.web.RequestHandler):
        def post(self):
            try:
                logging.debug("Got request: %s" % self.request.body)
                update = tornado.escape.json_decode(self.request.body)
                message = update['message']
                text = message.get('text')
                if text:
                    logging.info("MESSAGE FROM\t%s"
                                 % message['from']['id'])

                    if text[0] == '/':
                        command, *arguments = text.split(" ", 1)
                        if len(arguments):
                            arguments = arguments[0]
                        else:
                            arguments = ""
                        logging.debug("REQUEST\t%s\t%s\t'%s'" % (
                            message['from']['id'],
                            command,
                            arguments
                        ))
                        response = CMD.get(command, not_found)(arguments,
                                                               message)
<commit_msg>fix utf8<commit_after>#!/usr/bin/env python3

__author__ = 'm_messiah'
import logging
import signal
from requests import Session
import tornado.ioloop
import tornado.web
import tornado.escape
from os import environ as ENV

try:
    from bot_token import BOT_TOKEN
except:
    BOT_TOKEN = ENV["TOKEN"]
from commands import CMD


logging.basicConfig(level=logging.INFO)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.WARNING)


URL = "https://api.telegram.org/bot%s/" % BOT_TOKEN
MyURL = "https://messiah-bot.herokuapp.com"  # TODO: add url here, when get valid HTTPS

LAST_COMMAND = {}


def not_found(arguments, message):
    return {'chat_id': message['from']['id'],
            'text': "Command not found. Try /help"
            }

def send_reply(response):
    logging.debug("SENT\t%s" % response)
    if 'sticker' in response:
        api.post(URL + "sendSticker", data=response)
    elif 'text' in response:
        api.post(URL + "sendMessage", data=response)

# noinspection PyAbstractClass
class Handler(tornado.web.RequestHandler):
        def post(self):
            try:
                logging.debug("Got request: %s" % self.request.body)
                update = tornado.escape.json_decode(self.request.body)
                message = update['message']
                text = message.get('text')
                if text:
                    logging.info("MESSAGE FROM\t%s"
                                 % message['from']['username']
                                   if 'username' in message['from']
                                   else message['from']['id'])

                    if text[0] == '/':
                        command, *arguments = text.split(" ", 1)
                        if len(arguments):
                            arguments = arguments[0]
                        else:
                            arguments = ""
                        logging.debug("REQUEST\t%s\t%s\t'%s'" % (
                            message['from']['id'],
                            command.encode("utf8"),
                            arguments.encode("utf8")
                        ))
                        response = CMD.get(command, not_found)(arguments,
                                                               message)

{'fraction_non_alphanumeric': 0.11339507567201265, 'fraction_numerical': 0.0029365258640162636, 'mean_word_length': 1.6294536817102139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2431401', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1153, 'n_words': 259}