Toggle Navigation
Hatchery
Eggs
Angry Nerds podcast
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
# Onofficiele app # Feed te vinden op https://leukemensen.nl/angrynerds/feed.xml # Feed omgekat met: # https://api.rss2json.com/v1/api.json?rss_url=https://leukemensen.nl/angrynerds/feed.xml import ugfx, wifi, urequests, easydraw, time, appglue, audio, virtualtimers, orientation orientation.default() easydraw.msg("Loading...","Angry Nerds",True) #hack to be able to play audio, remove when fixed. audio.mixer_ctl_0(-128, 0) audio.mixer_ctl_1(128, 128) audio.play_mp3_stream("") audio.stop() # /hack wifi.connect() if not wifi.wait(30, True): easydraw.msg("WiFi failed.") time.sleep(2) appglue.home() easydraw.msg("Downloading list...") try: req = urequests.get("https://api.rss2json.com/v1/api.json?rss_url=https://leukemensen.nl/angrynerds/feed.xml") except: easydraw.msg("API failed.") time.sleep(2) appglue.home() easydraw.msg("Reading list...") try: data = req.json() except: easydraw.msg("JSON failed.") time.sleep(2) appglue.home() easydraw.msg("Aantal afleveringen: "+str(len(data["items"]))) easydraw.msg("Loading menu...") ugfx.clear(ugfx.WHITE) ugfx.display_image(0,0,"/lib/angry_nerds_podcast/angrynerds.png") options = ugfx.List(0,84,ugfx.width(),ugfx.height()-168) text = ugfx.Textbox(0, ugfx.height()-84, ugfx.width(), 84) for aflevering in data["items"]: options.add_item(aflevering["title"]) def btn_unhandled(pressed): #ugfx.clear(ugfx.WHITE) #options.visible(False) #text.visible(False) #ugfx.flush() #options.visible(True) ugfx.display_image(0,0,"/lib/angry_nerds_podcast/angrynerds.png") text.visible(True) options.visible(True) text.text(data["items"][options.selected_index()]["description"]) ugfx.flush() def btn_home(pressed): if pressed: appglue.home() def btn_play(pressed): global text if pressed: url = data["items"][options.selected_index()]["enclosure"]["link"] #text.text(data["items"][options.selected_index()]["description"]) print("URL",url) if audio.is_playing(): audio.stop() #easydraw.msg(data["items"][options.selected_index()]["title"], "Play", True) while audio.is_playing(): time.sleep(0.05) #easydraw.msg("Loading...") audio.play_mp3_stream(url) #easydraw.msg("Playing...") time.sleep(0.5) #options.visible(False) #ugfx.flush() options.visible(True) text.visible(True) ugfx.flush() def btn_stop(pressed): if pressed: if audio.is_playing(): audio.stop() #easydraw.msg(" ", "Stop", True) time.sleep(0.5) #options.visible(False) #ugfx.flush() options.visible(True) text.visible(True) ugfx.flush() def btn_volume_down(pressed): if pressed: audio.volume(audio.volume()-1) #easydraw.msg("Value: "+str(audio.volume()), "Volume", True) time.sleep(0.5) #options.visible(False) #ugfx.flush() options.visible(True) text.visible(True) ugfx.flush() def btn_volume_up(pressed): if pressed: audio.volume(audio.volume()+1) #easydraw.msg("Value: "+str(audio.volume()), "Volume", True) time.sleep(0.5) #options.visible(False) #ugfx.flush() options.visible(True) text.visible(True) ugfx.flush() text.text(data["items"][options.selected_index()]["description"]) ugfx.input_attach(ugfx.BTN_START, btn_home) ugfx.input_attach(ugfx.BTN_SELECT, btn_unhandled) ugfx.input_attach(ugfx.BTN_A, btn_play) ugfx.input_attach(ugfx.BTN_B, btn_stop) ugfx.input_attach(ugfx.JOY_UP, btn_unhandled) ugfx.input_attach(ugfx.JOY_DOWN, btn_unhandled) ugfx.input_attach(ugfx.JOY_LEFT, btn_volume_down) ugfx.input_attach(ugfx.JOY_RIGHT, btn_volume_up) ugfx.flush() def wifiTask(): if not wifi.status(): wifi.connect() return 5000 virtualtimers.activate(25) virtualtimers.new(0,wifiTask)