def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for articles in articles: bot.send_message(chat_id=update.message.chat_id, text=article) else: bot.send_message(chat_id=update.message.chat_id, text=reply) def echo_sticker(bot, update): bot.send_sticker(chat_id=update.message.chat_id, sticker=update.message.sticker.file_id) def error(bot, update): logger.error("Update '%s' caused error '%s'", update, update.error) # def message_handler(update, context: CallbackContext): # update.message.reply_text(text) bot = Bot(TOKEN) try: bot.set_webhook("https://48c9acd55480.ngrok.io/" + TOKEN) except Exception as e: print(e) dp = Dispatcher(bot, None) dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", _help)) dp.add_handler(CommandHandler("news", news)) dp.add_handler(MessageHandler(Filters.text, reply_text)) dp.add_handler(MessageHandler(Filters.sticker, echo_sticker)) dp.add_error_handler(error) if __name__ == "__main__": app.run(port=8443)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(update: Update, context: CallbackContext): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: context.bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: context.bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(update: Update, context: CallbackContext): """callback function for text message handler""" intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: update.message.reply_text(article['link']) else: update.message.reply_text(reply)
def reply_text(bot, update): """callback function for text message handler""" intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(update: Update, context: CallbackContext): intent, reply = get_reply( update.to_dict()['message']['text'], update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: update.message.reply_text(article['link']) else: update.message.reply_text(reply)
def reply_text(bot, update): # callback function for text message handler intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": # reply_text = "Ok! I will show you news with {}".format(reply) articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": reply_text = "Okay!Here's the news" articles = fetch_news(reply) for article in articles: update.message.reply_text(article['link']) else: update.message.reply_text(reply)
def reply_text(bot, update): """callback function for text message handler""" intent, reply = get_reply(update.message.text, update.message.chat_id) print("Reply : ",reply,"\nIntent :",intent) if reply == "": bot.send_message(chat_id=update.message.chat_id, text="Its beyond my reach.!") if intent == "topic": articles = fetch_news(reply) ## print(articles) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) #the get_reply function uses the chat_id as the session_id for multiple interactions with different users #also to prevent the bot to send the required text of one user to another #we are also receiving the intent from the return statement in the utils module if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) # reply_text = "Ok! I will show you the news with {}".format(reply) # bot.send_message(chat_id=update.message.chat_id, text=reply_text) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def reply(self): ties = session.query(Tie).all() for tie in ties: if '高' in tie.bar.name or '中' in tie.bar.name: self.driver.get(tie.url) # 将页面滚动条拖到底部 js = "var q=document.documentElement.scrollTop=10000" self.driver.execute_script(js) time.sleep(3) reply_content = get_reply() # 输入内容 ueditor_replace = self.driver.find_element_by_id( 'ueditor_replace') self.driver.execute_script( "arguments[0].innerHTML='<p>{}</p>'".format(reply_content), ueditor_replace) time.sleep(3) # 点击提交 button = self.driver.find_element_by_class_name( 'poster_submit') button.click() sleep_time = random.randint(5, 15) time.sleep(sleep_time)
def reply_text(bot, update): intent, reply = get_reply(update.message.text, update.message.chat_id) if intent == "get_news": articles = fetch_news(reply) for article in articles: bot.send_message(chat_id=update.message.chat_id, text=article['link']) elif intent == "Corona": Total, Active, Death, Recoverd = get_cases() cases = " 🇮🇳 India: Total \n Confirmed: {} \n Active: {} \n Deaths: {} \n Recovered: {}".format( Total, Active, Death, Recoverd) city = reply.get('geo-state') if city is not '': City_name, Total_city, Active_city, Death_city, Recoverd_city = get_cases_by_city( city) cases_by_city = " In {} Total \n Confirmed: {} \n Active: {} \n Deaths: {} \n Recovered: {}".format( City_name, Total_city, Active_city, Death_city, Recoverd_city) final = cases + "\n\n" + cases_by_city bot.send_message(chat_id=update.message.chat_id, text=final) else: bot.send_message(chat_id=update.message.chat_id, text=cases) else: bot.send_message(chat_id=update.message.chat_id, text=reply)
def __call__(self, asset_ids, download=True): result = [] # Download information about assets (by IDs) asset_list = get_page(self._session, OPENCOURSE_API_ASSETS_V1_URL, json=True, id=','.join(asset_ids)) # Create a map "asset_id => asset" for easier access asset_map = dict( (asset['id'], asset) for asset in asset_list['elements']) for asset_id in asset_ids: # Download each asset asset_dict = asset_map[asset_id] url = asset_dict['url']['url'].strip() data, content_type = None, None if download: reply = get_reply(self._session, url) if reply.status_code == 200: data = reply.content content_type = reply.headers.get('Content-Type') asset = Asset(id=asset_dict['id'].strip(), name=asset_dict['name'].strip(), type_name=asset_dict['typeName'].strip(), url=url, content_type=content_type, data=data) self._asset_mapping[asset.id] = asset result.append(asset) return result
def post_page_and_reply(session, url, data=None, headers=None, **kwargs): url = url.format(**kwargs) reply = get_reply(session, url, post=True, data=data, headers=headers) return reply.text, reply