I made this Toga app as a Bash one-liner:
python -c '
import toga
import urllib.request
import json
def fetch_json(url):
with urllib.request.urlopen(url) as response:
if response.getcode() == 200:
data = response.read()
return json.loads(data.decode("utf-8"))
else:
raise urllib.error.URLError(f"Failed to retrieve data. HTTP Error Code: {response.getcode()}")
class TogaDemo(toga.App):
def startup(self):
# Create the main window
self.main_window = toga.MainWindow()
data = fetch_json("https://datasette.io/content/datasette_repos.json")
table = toga.Table(
headings=data["columns"],
data=data["rows"]
)
self.main_window.content = table
self.main_window.show()
TogaDemo("Datasette Table", "io.datasette.toga-datasette").main_loop()
'