-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstar_bot.py
More file actions
30 lines (23 loc) · 759 Bytes
/
star_bot.py
File metadata and controls
30 lines (23 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from decouple import config
import requests
from telegram.ext import Updater, MessageHandler, Filters
token = config('TOKEN')
request_url = config('REQUEST_URL')
updater = Updater(token=token)
dispatcher = updater.dispatcher
def handler(bot, update):
api = requests.get(url=request_url)
response = api.json()
request = update.message.text
result = ""
for data in response:
if data['name'] != request:
continue
result = "Repository '%s' has %d Stars." % (request, data['stargazers_count'])
break
if result == "":
result = "Repository not found."
update.message.reply_text(result)
dispatcher.add_handler(MessageHandler(Filters.text, handler))
updater.start_polling()
updater.idle()