#!/bin/python3 from tkinter import * from tkinter.font import Font from PIL import Image import requests import urllib class RadioParadise(object): def __init__(self): self.load_api() def load_api(self): respons=requests.get("https://api.radioparadise.com/api/now_playing") rp_dict=respons.json() self.title=rp_dict["title"] self.artist=rp_dict["artist"] self.album=rp_dict["album"] self.year=rp_dict["year"] self.time=rp_dict["time"] self.jpg_path=rp_dict["cover"] return rp_dict def get_list(self): result=(self.title, self.artist, self.album, self.year, self.time) return result class AlbumCover(RadioParadise): def __init__(self, path): self.jpg_path=path def store_albumcover(self): rp_raw_image=requests.get(self.jpg_path).content rp_file=open("album_art.jpg", "wb") rp_file.write("rp_raw_image") rp_file.close() rp_convert_img=Image.open("album_art.jpg") rp_convert_img.save("album_art.gif") rp_convert_img.close() class RPViewer(Tk): def __init__(self, radioparadise, *args, **kwargs): super().__init__(*args, **kwargs) self.rp=radioparadise self.title("Radio Paradise Viewer") self.geometry("500x740") self.resizable(False,False) self.label=Label(self, font="Arial, 14", text="Radio Paradise now playing:") self.label.pack() self.button_quit=Button(self, text="Quit", command=self.quit) self.button_refresh=Button(self, text="Refresh", command=lambda: [self.rp.load_api(),self.refresh_textbox()]) self.button_quit.pack(side=BOTTOM) self.button_refresh.pack(side=TOP) self.font=Font(family="Arial", size=14) self.textbox=Text(self, height=6, width=50, font=self.font) self.textbox.insert("1.0", self.rp.get_list()) self.textbox.config(state=DISABLED) self.textbox.pack() def quit(self): exit() def refresh_textbox(self): self.textbox.config(state=NORMAL) self.textbox.delete("1.0", "end") self.textbox.insert("1.0", self.rp.get_list()) self.textbox.config(state=DISABLED) def main(): rp_play=RadioParadise() app=RPViewer(rp_play) app.mainloop() if __name__=="__main__": main()