From 147085c383aec097b920d20eae33525043a97197 Mon Sep 17 00:00:00 2001 From: Wiktor Zykubek Date: Mon, 12 Jun 2023 21:42:10 +0200 Subject: [PATCH] Display stations in group after selection --- mainwindow.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mainwindow.py b/mainwindow.py index fc658f9..97c4015 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -17,14 +17,28 @@ class MainWindow(QMainWindow): super().__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) + self.stations_slug = json.loads(requests.get( + "https://open.fm/radio/api/v2/ofm/stations_slug.json" + ).text) self.getGroups() + self.ui.groupslistWidget.itemClicked.connect(self.getStations) def getGroups(self): - resp = requests.get("https://open.fm/radio/api/v2/ofm/stations_slug.json") - json_ = json.loads(resp.text) - for el in json_["groups"]: + for el in self.stations_slug["groups"]: self.ui.groupslistWidget.addItem(el["name"]) + def getStations(self): + group = self.ui.groupslistWidget.selectedItems()[0].text() + group_id = None + for i in self.stations_slug["groups"]: + if i["name"] == group: + group_id = i["id"] + + self.ui.stationslistWidget.clear() + for ch in self.stations_slug["channels"]: + if ch["group_id"] == group_id: + self.ui.stationslistWidget.addItem(ch["name"]) + if __name__ == "__main__": app = QApplication(sys.argv)