aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinwei Zhao <[email protected]>2017-02-01 21:34:30 +0800
committerJinwei Zhao <[email protected]>2017-02-01 21:41:54 +0800
commit4d2a94988cf0e51b51bfc4d6f5e73aa6351402c6 (patch)
tree5b9d41e143144effe0d0ffe3bdd89e9de82fcdeb /searchbot.py
parent9e8f476d124ae81b0434e17cd6fdb13d981e06ae (diff)
downloadCOMM2TG-4d2a94988cf0e51b51bfc4d6f5e73aa6351402c6.tar.gz
refactor
Diffstat (limited to 'searchbot.py')
-rw-r--r--searchbot.py41
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 @@
1from pymongo import MongoClient
2from telegram.ext import Updater, CommandHandler
3import logging
4# Enable logging
5logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
6 level=logging.DEBUG)
7logger = logging.getLogger(__name__)
8
9
10def 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
22def start(bot, update):
23 bot.sendMessage(update.message.chat_id, text="Hi! Use /search agentid to start, no need for @")
24
25
26def error(bot, update, error):
27 logger.warn('Update "%s" caused error "%s"' % (update, error))
28
29
30def 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
40if __name__ == "__main__":
41 main()
Powered by cgit v1.2.3 (git 2.41.0)