-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
33 lines (26 loc) · 821 Bytes
/
bot.py
File metadata and controls
33 lines (26 loc) · 821 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
31
32
33
from telegram.ext import Updater, CommandHandler
import requests
import re
def get_url():
contents = requests.get('https://random.dog/woof.json').json()
url = contents['url']
return url
def bop(bot, update):
url = get_url()
chat_id = update.message.chat_id
bot.send_photo(chat_id=chat_id, photo=url)
def main():
updater = Updater('773688361:AAHOAGcK_6-YSPJ-ZsLzUpBKeAwt2_kNex0')
dp = updater.dispatcher
dp.add_handler(CommandHandler('bop',bop))
updater.start_polling()
updater.idle()
def get_image_url():
allowed_extension = ['jpg','jpeg','png']
file_extension = ''
while file_extension not in allowed_extension:
url = get_url()
file_extension = re.search("([^.]*)$",url).group(1).lower()
return url
if __name__ == '__main__':
main()