commit 4af3e17d693dd36461679d35db47643d9c5cd063 Author: Megamichi Date: Fri Jul 19 12:14:56 2024 +0100 init diff --git a/__pycache__/xmlhandler.cpython-311.pyc b/__pycache__/xmlhandler.cpython-311.pyc new file mode 100644 index 0000000..87e3202 Binary files /dev/null and b/__pycache__/xmlhandler.cpython-311.pyc differ diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..fe23769 Binary files /dev/null and b/assets/icon.png differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..d3e59a2 --- /dev/null +++ b/main.py @@ -0,0 +1,86 @@ +import flet as ft +import xmlhandler + + +def main(page: ft.Page): + ## Funkktionen + def open_url(url): + page.launch_url(url) + + def create_overview(category): + magazine.clear() + for item in bookshelf_dict["PUBS"][category]["ITEM"]: + if type(item["TITLE"]) == list: # überspringe beginnerguide 4th edition + continue + magazine.append( + ft.Container( + content=ft.Row( + controls=[ + ft.Column( + controls=[ + ft.Image(src=item["COVER"], width=100), + ft.FloatingActionButton( + "PDF", + width=100, + on_click=lambda _: open_url(page, item["PDF"]), + ), + ], + ), + ft.Column( + controls=[ + ft.Text(item["TITLE"], max_lines=2), + ft.Text(item["DESC"], size=12, max_lines=-1), + ], + expand=True, + ), + ], + ), + bgcolor=ft.colors.INDIGO_600, + border_radius=8, + padding=6, + ) + ) + + def navigationbar_change(e): + category = categorys[e.control.selected_index] + create_overview(category) + page.update() + + ## Variablen + magazine = [] + category = "MAGPI" + categorys = ["MAGPI", "HACKSPACE", "BOOKS"] + + def reload(e=None): + global bookshelf_dict + bookshelf_dict = xmlhandler.reload() + create_overview(category) + + print("reloaded") + + reload() + + page.scroll = True + page.theme_mode = ft.ThemeMode.DARK + page.navigation_bar = ft.NavigationBar( + destinations=[ + ft.NavigationBarDestination(icon=ft.icons.BOOK, label="MagPi"), + ft.NavigationBarDestination(icon=ft.icons.BOOK, label="Hackspace"), + ft.NavigationBarDestination(icon=ft.icons.BOOK, label="Books"), + ], + on_change=navigationbar_change, + ) + page.appbar = ft.AppBar( + # leading_width=40, + title=ft.Text("RBookshelf"), + center_title=True, + bgcolor=ft.colors.SURFACE_VARIANT, + actions=[ + ft.IconButton(ft.icons.DOWNLOAD, on_click=reload), + ], + ) + page.add(ft.Column(controls=magazine, spacing=10)) + page.add(page.navigation_bar) + + +ft.app(main) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d54c7ec --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flet==0.22.* \ No newline at end of file diff --git a/xmlhandler.py b/xmlhandler.py new file mode 100644 index 0000000..fe45c42 --- /dev/null +++ b/xmlhandler.py @@ -0,0 +1,8 @@ +import requests +import xmltodict +import json + +def reload(): + bookshelf_xml = requests.get("https://magpi.raspberrypi.com/bookshelf.xml") + return xmltodict.parse(bookshelf_xml.content) +