Display stations in group after selection
This commit is contained in:
parent
4775c10a0e
commit
147085c383
@ -17,14 +17,28 @@ class MainWindow(QMainWindow):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
self.ui.setupUi(self)
|
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.getGroups()
|
||||||
|
self.ui.groupslistWidget.itemClicked.connect(self.getStations)
|
||||||
|
|
||||||
def getGroups(self):
|
def getGroups(self):
|
||||||
resp = requests.get("https://open.fm/radio/api/v2/ofm/stations_slug.json")
|
for el in self.stations_slug["groups"]:
|
||||||
json_ = json.loads(resp.text)
|
|
||||||
for el in json_["groups"]:
|
|
||||||
self.ui.groupslistWidget.addItem(el["name"])
|
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__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user