Cleanup
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 215 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 51 KiB |
@@ -1,79 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
from tkinter import *
|
||||
from tkinter.font import Font
|
||||
import requests
|
||||
import urllib
|
||||
from PIL import Image
|
||||
|
||||
def get_rp():
|
||||
# Get API respons
|
||||
respons = requests.get("https://api.radioparadise.com/api/now_playing")
|
||||
tekst = respons.json()
|
||||
|
||||
# Selection of data to use
|
||||
title = tekst["title"]
|
||||
artist = tekst["artist"]
|
||||
album = tekst["album"]
|
||||
year = tekst["year"]
|
||||
time = tekst["time"]
|
||||
jpg_path = tekst["cover"]
|
||||
|
||||
# Return caller standard information
|
||||
message = (f'Titel: {title}\nArtiest: {artist}\nAlbum: {album}\nJaar: {year}\nTijd: {time}')
|
||||
return message,jpg_path
|
||||
|
||||
def rp_quit():
|
||||
exit()
|
||||
|
||||
# Refresh data from Radio Paradise when asked
|
||||
def rp_refresh():
|
||||
rp_tekstbox.delete("1.0", "end")
|
||||
rp_tekstbox.insert("1.0", get_rp()[0])
|
||||
|
||||
# Convert the jpg-file from RP to a manageable gif
|
||||
get_and_convert_art()
|
||||
|
||||
# Load the image into the label
|
||||
img = PhotoImage(file="album_art.gif", format='gif')
|
||||
image_lbl.configure(image=img)
|
||||
image_lbl.image=img
|
||||
|
||||
# Converts and stores a .jpg into a .gif
|
||||
def get_and_convert_art():
|
||||
rp_image_path = get_rp()[1]
|
||||
rp_image_file = requests.get(rp_image_path).content
|
||||
|
||||
rp_file=open("album_art.jpg", 'wb')
|
||||
rp_file.write(rp_image_file)
|
||||
rp_file.close()
|
||||
rp_image = Image.open("album_art.jpg")
|
||||
rp_image.save("album_art.gif")
|
||||
rp_image.close()
|
||||
|
||||
if __name__=="__main__":
|
||||
|
||||
window=Tk()
|
||||
window.title("Radio Paradise")
|
||||
|
||||
rp_font=Font(family="Arial", size=14)
|
||||
rp_tekstbox=Text(window, height=6, width=50, font=rp_font)
|
||||
|
||||
label=Label(window, font="Arial, 14", text="Radio Paradise now playing")
|
||||
label.pack()
|
||||
|
||||
button_quit=Button(window, text="Quit", command=rp_quit)
|
||||
button_refresh=Button(window, text="Refresh", command=rp_refresh)
|
||||
button_quit.pack(side=BOTTOM)
|
||||
button_refresh.pack(side=TOP)
|
||||
|
||||
rp_tekstbox.insert("1.0", get_rp()[0])
|
||||
rp_tekstbox.pack()
|
||||
|
||||
get_and_convert_art()
|
||||
|
||||
img = PhotoImage(file="album_art.gif", format='gif')
|
||||
image_lbl = Label(window, image=img)
|
||||
image_lbl.pack()
|
||||
|
||||
window.mainloop()
|
||||
@@ -1,12 +0,0 @@
|
||||
self.title=None
|
||||
self.artist=None
|
||||
self.album=None
|
||||
self.year=None
|
||||
self.time=None
|
||||
self.jpg_path=None
|
||||
|
||||
Probleem:
|
||||
Bij drukken op "refresh" button gebeurt er niets. De class RadioParadise initialiseerd wel, maar na een update
|
||||
wordt de method load_api() aangeroepen vanuit de button "refresh" met lambda functie voor 2 acties.
|
||||
De method load_api() vult natuurlijk niet de properties/variables van de class, hoewel deze method wel wordt aangeroepen.
|
||||
Oplossing is de init van de class en de eerste object die de API call moet doen.
|
||||
Reference in New Issue
Block a user