Skip to content

Instantly share code, notes, and snippets.

@StackZeroSec
Created October 4, 2022 03:07
Show Gist options
  • Save StackZeroSec/917c31e2a375405f74ef0a38a4a16de0 to your computer and use it in GitHub Desktop.
Save StackZeroSec/917c31e2a375405f74ef0a38a4a16de0 to your computer and use it in GitHub Desktop.
An applicattion which uses Borded API to suggest you a random activity
import requests
import json
import tkinter
from types import SimpleNamespace
BASE_URL = "http://www.boredapi.com/api/activity"
class Window():
def __init__(self):
self.initUI()
def initUI(self):
self.master = tkinter.Tk()
self.master.title("Activities Advisor")
self.viewText = tkinter.Text(self.master)
self.viewText.pack(side=tkinter.TOP)
closeButton = tkinter.Button(self.master, text="Close", command=self.master.quit)
tkinter.Button()
closeButton.pack(side=tkinter.RIGHT, padx=5, pady=5)
newButton = tkinter.Button(self.master, text="New", command= lambda : self.settext(get_random_activity()))
newButton.pack(side=tkinter.RIGHT)
self.master.mainloop()
def settext(self, json_activity):
activity = SimpleNamespace(**json_activity)
text = f"Activity: {activity.activity}\n" \
f"Accessibility:{activity.accessibility} \n" \
f"Type: {activity.type}\n" \
f"Participants: {activity.participants}\n" \
f"price: {activity.price}\n"
self.viewText.delete(1.0, tkinter.END)
self.viewText.insert(tkinter.END, text)
def get_random_activity():
url = BASE_URL
response=requests.get(url)
return json.loads(response.text)
if __name__=="__main__":
app = Window()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment