-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetquote.py
executable file
·33 lines (28 loc) · 947 Bytes
/
getquote.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
# By Jonas Johansson
# For the KoboHUB Dashboard
from requests import get
from requests.exceptions import RequestException
from dataclasses import dataclass
@dataclass
class quote_summary:
quote_text: str
quote_author :str
def quoteoftheday():
quote_data = ""
try:
response = get('http://api.quotable.io/random')
if response.ok:
quote_body = response.json()
#quote_body = json.loads(rawresponse)
#print(rawresponse)
#print(quote_body['quoteText'])
#print(quote_body['quoteAuthor'])
quote_text = quote_body['content']
quote_author = quote_body['author']
quote_data = quote_summary(quote_text, quote_author)
except RequestException as e:
print("Error getting quote")
quote_text = ""
quote_author = ""
quote_data = quote_summary(quote_text, quote_author)
return quote_data