-
Notifications
You must be signed in to change notification settings - Fork 0
/
fun_fact_generator.py
55 lines (42 loc) · 1.61 KB
/
fun_fact_generator.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
import requests
from pywebio.input import *
from pywebio.output import *
from pywebio.session import *
def get_fun_fact(_):
# Clear the above screen
clear()
put_html("<p align=""left""><h2><img src=""https://\
media.geeksforgeeks.org/wp-content/uploads/\
20210720224119/MessagingHappyicon.png"" width=""7%""> \
Fun Fact Generator</h2></p>
")
# URL from where we will fetch the data
url = "https://uselessfacts.jsph.pl/random.json?language=en"
# Use GET request
response = requests.request("GET", url)
# Load the request in json file
data = json.loads(response.text)
# we will need 'text' from the list, so
# pass 'text' in the list
useless_fact = data['text']
# Put the facts in the blue colour
# Put the click me button
style(put_text(useless_fact), 'color:blue; font-size: 30px')
put_buttons(
[dict(label='Click me', value='outline-success',
color='outline-success')], onclick=get_fun_fact)
# Driver Function
if __name__ == '__main__':
# Put a heading "Fun Fact Generator"
put_html("<p align=""left""><h2><img src=""https://media.\
geeksforgeeks.org/wp-content/uploads/20210720224119\
/MessagingHappyicon.png"" width=""7%""> \
Fun Fact Generator</h2></p>
")
# hold the session for long time
# Put a Click me button
put_buttons(
[dict(label='Click me', value='outline-success',
color='outline-success')], onclick=get_fun_fact)
hold()