From 4d2a94988cf0e51b51bfc4d6f5e73aa6351402c6 Mon Sep 17 00:00:00 2001 From: Jinwei Zhao Date: Wed, 1 Feb 2017 21:34:30 +0800 Subject: refactor --- searchbot.py | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 searchbot.py (limited to 'searchbot.py') diff --git a/searchbot.py b/searchbot.py deleted file mode 100644 index ee504d5..0000000 --- a/searchbot.py +++ /dev/null @@ -1,41 +0,0 @@ -from pymongo import MongoClient -from telegram.ext import Updater, CommandHandler -import logging -# Enable logging -logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.DEBUG) -logger = logging.getLogger(__name__) - - -def search(bot, update, args): - agentid = args[0] - print(agentid) - conn = MongoClient('Mongo Address') - db = conn['COMM_Hangzhou'] - collection = db.entries - res = collection.find({"$text": {"$search": agentid}}) - for i in res: - print(i) - bot.sendMessage(update.message.chat_id, text=str(i)) - - -def start(bot, update): - bot.sendMessage(update.message.chat_id, text="Hi! Use /search agentid to start, no need for @") - - -def error(bot, update, error): - logger.warn('Update "%s" caused error "%s"' % (update, error)) - - -def main(): - updater = Updater('Telegram Bot ID') - dp = updater.dispatcher - dp.add_handler(CommandHandler("start", start)) - dp.add_handler(CommandHandler("help", start)) - dp.add_handler(CommandHandler("search", search, pass_args=True)) - dp.add_error_handler(error) - updater.start_polling() - updater.idle() - -if __name__ == "__main__": - main() -- cgit v1.2.3