<commit_before># -*- coding: utf-8 -*-

import telegram
from settings import TELEGRAM_TOKEN
from pygeocoder import Geocoder
import pygeolib
from model import subscribe, unsubscribe
from utils import lat_lon_to_cell

bot = telegram.Bot(token=TELEGRAM_TOKEN)

commands = [
    '/subscribe Санкт-Петербург',
    '/unsubscribe'
]


def geo_code(address):
    try:
        business_geocoder = Geocoder(None, 'MY_API_KEY')
        results = business_geocoder.geocode(address)
        return results.latitude, results.longitude
    except pygeolib.GeocoderError:
        return None


def reply(update, message):
    bot.sendMessage(
        chat_id=update.message.chat_id,
        reply_to_message_id=update.message.message_id,
        text=message,
    )


def reply_by_chat_id(chat_id, message):
    bot.sendMessage(
        chat_id=chat_id,
        text=message,
    )


def main():
    offset = 0
    print 'Press Ctrl+C to kill...'
    while True:
        updates = bot.getUpdates(offset=offset+1)
        for update in updates:
            text = update.message.text
            text_split = text.split(' ', 1)
            command, arguments = text_split[0], None
            if len(text_split) > 1:
                arguments = text_split[1]

            if command == '/subscribe':
                geo = geo_code(arguments)
                if geo is None:
                    reply(update, "Не удалось определить координаты места")
                else:
                    geo_id = lat_lon_to_cell(geo[0], geo[1])
                    subscribe(update.message.chat_id, arguments, geo_id)
                    reply(update, "Вы подписаны и получите уведомление о сиянии в Ваше регионе как только так сразу!")

            elif command == '/unsubscribe':
                unsubscribe(update.message.chat_id)
                reply(update, "Вы успешно отписаны.")

            else:
                reply(update, "Неизвестная комманда")<commit_msg>attach location on map to verify that geocoder worked right<commit_after># -*- coding: utf-8 -*-

import telegram
from settings import TELEGRAM_TOKEN
from pygeocoder import Geocoder
import pygeolib
from model import subscribe, unsubscribe
from utils import lat_lon_to_cell

bot = telegram.Bot(token=TELEGRAM_TOKEN)

commands = [
    '/subscribe Санкт-Петербург',
    '/unsubscribe'
]


def geo_code(address):
    try:
        business_geocoder = Geocoder(None, 'MY_API_KEY')
        results = business_geocoder.geocode(address)
        return results.latitude, results.longitude
    except pygeolib.GeocoderError:
        return None


def reply(update, message):
    bot.sendMessage(
        chat_id=update.message.chat_id,
        reply_to_message_id=update.message.message_id,
        text=message,
    )


def reply_by_chat_id(chat_id, message):
    bot.sendMessage(
        chat_id=chat_id,
        text=message,
    )


def main():
    offset = 0
    print 'Press Ctrl+C to kill...'
    while True:
        updates = bot.getUpdates(offset=offset+1)
        for update in updates:
            text = update.message.text
            text_split = text.split(' ', 1)
            command, arguments = text_split[0], None
            if len(text_split) > 1:
                arguments = text_split[1]

            if command == '/subscribe':
                geo = geo_code(arguments)
                if geo is None:
                    reply(update, "Не удалось определить координаты места")
                else:
                    geo_id = lat_lon_to_cell(geo[0], geo[1])
                    subscribe(update.message.chat_id, arguments, geo_id)
                    reply(update, """Вы подписаны и получите уведомление о сиянии в Ваше регионе как только так сразу!
На всякий случай проверьте, что мы правильно определили Ваше местоположение.""")
                    bot.sendLocation(
                        chat_id=update.message.chat_id,
                        latitude=geo[0],
                        longitude=geo[1],
                    )

            elif command == '/unsubscribe':
                unsubscribe(update.message.chat_id)
                reply(update, "Вы успешно отписаны.")

            else:
                reply(update, "Неизвестная комманда")
{'fraction_non_alphanumeric': 0.0876068376068376, 'fraction_numerical': 0.004748338081671415, 'mean_word_length': 2.077428780131483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908326', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1307, 'n_words': 298}