예제 #1
0
        _LOGGER.info('New apartment amount: %s', len(new_apartments))
        for notifier in self.notifiers:
            _LOGGER.info('Notifying with %s', notifier.__class__.__name__)
            notifier.notify(new_apartments)

        _LOGGER.info("Saving results")
        self.user.last_check_datetime = current_check_datetime
        self.user.save()
        _LOGGER.info('Finished...')


if __name__ == '__main__':
    from apartment_notifier.stores import JsonFileStore, FireStore, ObjectDoesNotExist
    from telegram_bot_mini.bot_api import TelegramBotApi
    logging.config.dictConfig(settings.LOGGING)
    # store = JsonFileStore(settings.store)
    store = FireStore()
    pk = 0
    try:
        user = store.get(pk)
    except ObjectDoesNotExist:
        print('Object does not exist. Create new:')
        chat_id = int(input('chat_id: '))
        onlinerby_url = input('onlinerby_url: ').strip()
        user = User(pk, chat_id, onlinerby_url=onlinerby_url, store=store)
        user.save()
    print(user)
    tg_bot_api = TelegramBotApi(settings.telegram_api_key)
    runner = Runner(settings, user, tg_bot_api)
    runner.run()
예제 #2
0
import logging

from flask import Flask, request

from telegram_bot_mini.bot import Bot
from telegram_bot_mini.bot_api import TelegramBotApi

_LOGGER = logging.getLogger(__name__)
WEBHOOK_TOKEN = 'longsecuretoken'
app = Flask(__name__)
bot_api = TelegramBotApi('123456789:ABCDEFGH123456-12345678912345678912')
bot = Bot(bot_api)


@app.route(f'/tg/{WEBHOOK_TOKEN}', methods=['POST'])
def telegram_webhook():
    content = request.get_json()
    bot.handle_update(content)
    return 'OK'


@bot.command('/start', '')
def start(api: TelegramBotApi, update):
    first_name = update['message']['from'].get('first_name', '%username%')
    api.send_message(update['message']['chat']['id'], f'Hello {first_name}!')


@bot.command('/whoami', '/whoami - show info about your account')
def whoami(api: TelegramBotApi, update):
    name = update['message']['from'].get(
        'first_name') or update['message']['from'].get('username')