diff options
Diffstat (limited to 'searchbot.py')
-rw-r--r-- | searchbot.py | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/searchbot.py b/searchbot.py deleted file mode 100644 index ee504d5..0000000 --- a/searchbot.py +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | from pymongo import MongoClient | ||
2 | from telegram.ext import Updater, CommandHandler | ||
3 | import logging | ||
4 | # Enable logging | ||
5 | logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | ||
6 | level=logging.DEBUG) | ||
7 | logger = logging.getLogger(__name__) | ||
8 | |||
9 | |||
10 | def search(bot, update, args): | ||
11 | agentid = args[0] | ||
12 | print(agentid) | ||
13 | conn = MongoClient('Mongo Address') | ||
14 | db = conn['COMM_Hangzhou'] | ||
15 | collection = db.entries | ||
16 | res = collection.find({"$text": {"$search": agentid}}) | ||
17 | for i in res: | ||
18 | print(i) | ||
19 | bot.sendMessage(update.message.chat_id, text=str(i)) | ||
20 | |||
21 | |||
22 | def start(bot, update): | ||
23 | bot.sendMessage(update.message.chat_id, text="Hi! Use /search agentid to start, no need for @") | ||
24 | |||
25 | |||
26 | def error(bot, update, error): | ||
27 | logger.warn('Update "%s" caused error "%s"' % (update, error)) | ||
28 | |||
29 | |||
30 | def main(): | ||
31 | updater = Updater('Telegram Bot ID') | ||
32 | dp = updater.dispatcher | ||
33 | dp.add_handler(CommandHandler("start", start)) | ||
34 | dp.add_handler(CommandHandler("help", start)) | ||
35 | dp.add_handler(CommandHandler("search", search, pass_args=True)) | ||
36 | dp.add_error_handler(error) | ||
37 | updater.start_polling() | ||
38 | updater.idle() | ||
39 | |||
40 | if __name__ == "__main__": | ||
41 | main() | ||