-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_assets.py
41 lines (31 loc) · 1.15 KB
/
get_assets.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
31
32
33
34
35
36
37
38
39
40
41
import requests
import json
def fetch_shiba():
# Get the Shiba Inu image url from the Shiba API
shiba_api = "http://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true"
print("Fetching shiba")
try:
res = requests.get(shiba_api)
except:
print("Error while calling API")
# Parse the results and extract the url and image extension
print("Image successfully fetched")
data = res.text
parsed_url = json.loads(data)[0]
image_extension = parsed_url.split('.')[-1]
# Download the shiba image to later upload as media and tweet
img_data = requests.get(parsed_url).content
with open('shiba.' + image_extension, 'wb') as handler:
handler.write(img_data)
def fetch_quote():
# Get the inspirational quote from the quote API
quote_api = "https://zenquotes.io/api/random"
print("Fetching quote")
try:
res = requests.get(quote_api)
except:
print("Error while calling API")
# Parse the results and return quote and author
data = res.json()[0]
print("Quote successfully fetched.")
return {'quote': data['q'], 'author': data['a']}