Skip to content

It will create interesting facts at random and display them on the web interface.

Notifications You must be signed in to change notification settings

triposat/Fun_Fact_Generator_Web_App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation


Prettier Size
sds

Essentially, it will create interesting facts at random and display them on the web interface. This script will retrieve data from uselessfacts.jsph.pl with the help of GET method, and we will use the requests and the JSON module to acquire and load the data respectively. After the data has been loaded, just pass the text within the dictionary so that we can only get the jokes. For creating a simple and interactive interface on the web, we will use the PyWebIO module.

Installation:

pip install pywebio

Import the modules:

import json
import requests
from pywebio.input import *
from pywebio.output import *
from pywebio.session import *

Stepwise explanation:

  • Import all the required modules
  • Send GET requests with the requests.request() method, and use the json.loads() function to parse a valid JSON message and transform it to a Python Dictionary. Since the requests function will create a dictionary of items, and we only need text, so we will pass response.text inside the json module.
  • Now, because we need the text, i.e. Facts, we will pass the text within the data list and print the facts using the style function defined in the pywebio module. Because data is a dictionary of random jokes involving several useless items, we will just get the text section.
  • Read complete article here

Output:

About

It will create interesting facts at random and display them on the web interface.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages