You can download this code by clicking the button below.
This code is now available for download.
This code defines a Kivy application that randomly selects one of three APIs to generate a greeting. It can display a random quote, a random name from a user, or a random meme link.
Technology Stack : Kivy, requests
Code Type : Kivy App
Code Difficulty : Intermediate
from kivy.app import App
from kivy.uix.label import Label
from random import choice
import requests
def generate_random_greeting():
urls = [
"https://api.quotable.io/random",
"https://randomuser.me/api/?results=1",
"https://api.imgflip.com/get_memes"
]
response = requests.get(choice(urls))
data = response.json()
if "quote" in data:
return f"Hello, {data['content']} - {data['author']}"
elif "name" in data:
return f"Hello, {data['results'][0]['name']['first']} {data['results'][0]['name']['last']}"
elif "memes" in data:
return f"Hello, check out this meme: {data['data'][0]['url']}"
class GreetingApp(App):
def build(self):
return Label(text=generate_random_greeting())
GreetingApp().run()