pos = text_lower.index('нет мест') if pos == 0 or not ('а' <= text_lower[pos - 1] <= 'я'): continue for user in User.objects.filter(status=True): BotWrapper.BOT.sendMessage(user.user_id, "{0}: {1}".format( db_post.date + timedelta(hours=3), text)) #, disable_notification=(user.user_id < 0)) if __name__ == '__main__': get_connect() BotWrapper.BOT = telepot.Bot(config.BOT_TOKEN) ml = MessageLoop(BotWrapper.BOT, handle_message) ml.run_as_thread() while True: status = get_status() def printstatus(message): status.status = message status.save() print(message) printstatus("Feed") try: update_feed_messages() except: printstatus("Error") printstatus("Loop")
def send_inline_message(telegram, data, call_back="ack"): chat_id = get_chat_ids().get(telegram) text = '[%s](%s) %s: %s - %s on %s\n%s' % ( data['short_id'], '%s/#/alert/%s' % (config.ALERTA_DASHBOARD_URL, data['id']), data['environment'], data['severity'], data['event'], data['resource'], data['text']) keyboard = InlineKeyboardMarkup(inline_keyboard=[[ { 'text': 'ack', 'callback_data': 'ack' }, { 'text': 'close', 'callback_data': 'close' }, ]]) try: message = bot.sendMessage(chat_id, text, parse_mode='Markdown', reply_markup=keyboard) except Exception as e: raise RuntimeError("Telegram Error - %s", e) return message if __name__ == "__main__": message_loop.run_as_thread() app.run(debug=True, use_reloader=False)
import json import logging import time import telepot from telepot.loop import MessageLoop from sheets import Sheets from telegram import Handler if __name__ == '__main__': logging.basicConfig(level=logging.INFO) with open('config.json') as fh: config = json.load(fh) bot = telepot.Bot(config['telegram']['token']) sheet = Sheets(config['sheets']) # # Optionally register callbacks for new accounting periods here: # sheet.new_ap_supervisor.register_callback() handler = Handler(bot, sheet, config['telegram']) loop = MessageLoop(bot, handler.handle) loop.run_as_thread() while True: time.sleep(10)