forked from NicolasParaskevas/catbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat.py
30 lines (27 loc) · 1020 Bytes
/
cat.py
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
import random
import requests
class Cat():
#genereate random meow
def meow_back(self):
random.seed()
e_number = random.randrange(1,5)
o_number = random.randrange(1,5)
reply = "m" + (e_number*"e") + (o_number*"o") + "w!"
return reply
#right now limit to 1 fact per request
def send_fact(self):
resp = requests.get('https://catfact.ninja/facts?limit=1')
if resp.status_code == 200:
item = resp.json()
#return the first fact
for data in item['data']:
return data['fact']
else:
return "API catfact.ninja returned HTTP status code {}".format(resp.status_code)
def send_image(self):
resp = requests.get('https://api.thecatapi.com/v1/images/search')
if resp.status_code == 200:
for item in resp.json():
return item['url']
else:
return "API thecatapi.com returned HTTP status code {}".format(resp.status_code)