コード例 #1
0
ファイル: bot.py プロジェクト: ChinaraIsabaeva/btcprices_bot
 def create_inline_message(self, updates):
     text = get_prices()
     if updates['query'] in 'btcprices':
         results = [{'type': 'article', 'title': 'price', 'message_text': text, 'id': updates['id']+'/0'}]
     else:
         results = [{'type': 'article', 'title': 'help', 'message_text': HELP_MSG, 'id': updates['id']+'/0'}]
     return {'inline_query_id': updates['id'], 'results': json.dumps(results)}
コード例 #2
0
def send_prices_by_alert():
    cursor = connection.cursor(cursor_factory=RealDictCursor)
    cursor.execute("SELECT chat_id, alarm, alarm_type FROM alarms;")
    query = json.dumps(cursor.fetchall(), cls=MyEncoder)
    data = json.loads(query)
    current_hour = datetime.datetime.now().time().hour
    bot = Bot(TOKEN)
    connection.close()
    for row in data:
        if row['alarm_type'] == 'hourly':
            chat_id = row['chat_id']
            text = get_prices()
            bot.send_daily_msg(chat_id, text)
        else:
            if current_hour == row['alarm']:
                chat_id = row['chat_id']
                text = get_prices()
                bot.send_daily_msg(chat_id, text)
コード例 #3
0
ファイル: bot.py プロジェクト: ChinaraIsabaeva/btcprices_bot
 def create_text_message(self, updates):
     if updates['text'] != '':
         received_msg = updates['text']
         if any(received_msg.lower() in substr for substr in ['btcprices', 'цена', '/price']):
             text = get_prices()
         elif any(received_msg.lower() in substr for substr in ['/feedback', 'rate and review']):
             text = 'Please rate and leave your review at: https://storebot.me/bot/btcprices_bot'
         else:
             text =  HELP_MSG
     else:
         text = "I understand only text messages"
     keyboard = [['price', 'help'], ['rate and review', ]]
     message = dict(chat_id=updates['chat_id'], text=text, reply_markup=dict(keyboard=keyboard, resize_keyboard=True))
     return message
コード例 #4
0
ファイル: bot.py プロジェクト: ChinaraIsabaeva/chee-bot
 def create_text_message(self, updates):
     keyboard = [['price', 'help', 'rate and review'], [ 'set alarm', 'delete alarm']]
     if updates['text'] != '':
         received_msg = updates['text']
         if any(received_msg.lower() in substr for substr in ['btcprices', 'цена', '/price']):
             text = get_prices()
         elif any(received_msg.lower() in substr for substr in ['/feedback', 'rate and review']):
             text = 'Please rate and leave your review at: https://storebot.me/bot/btcprices_bot'
         elif received_msg.lower() == 'set alarm':
             text = 'You can set alarm to receive prices daily or hourly.'
             keyboard = [['daily', 'hourly'], ]
         elif received_msg.lower() == 'hourly':
             text = save_alarms_settings(updates['date'], updates['chat_id'], 'hourly')
         elif received_msg.lower() == 'daily':
             text = save_alarms_settings(updates['date'], updates['chat_id'], 'daily')
         elif received_msg.lower() == 'delete alarm':
             text = delete_alarm_settings(updates['chat_id'])
         else:
             text = HELP_MSG
     else:
         text = "I understand only text messages"
     
     message = dict(chat_id=updates['chat_id'], text=text, reply_markup=dict(keyboard=keyboard, resize_keyboard=True))
     return message