imaginaryfriend/src/handler/commands/meow.py

16 lines
418 B
Python
Raw Normal View History

2017-04-16 15:35:12 +02:00
from .base import Base
from urllib.request import build_opener, HTTPRedirectHandler
import json
2017-04-16 15:35:12 +02:00
class Meow(Base):
name = 'meow'
aliases = [':3', '=3']
2017-08-19 17:19:21 +02:00
def execute(self, command):
2017-04-16 15:35:12 +02:00
opener = build_opener(HTTPRedirectHandler)
with opener.open('https://api.thecatapi.com/v1/images/search') as r:
cats = json.loads(r.read())
2017-04-16 15:35:12 +02:00
self.send_photo(command, photo=cats[0]['url'])