def update_profile_img(form_img, user_name): _, ext = get_ext(form_img.filename) pic_name = user_name + ext pic_path = join(current_app.root_path, 'static/images/profiles', pic_name) i = Image.open(form_img) i.thumbnail((150, 150)) i.save(pic_path) return pic_name
def query(a_query=store_conn['query_sql'], a_blob_url=store_conn['file_csv'], a_sas_key=store_conn['access_key']): """ Helper to query json and/or csv files on a Blob/Datalake """ result_set = [] start = time.perf_counter() #Get the file extension/type a_file_name, a_file_type = get_ext(a_blob_url) blob_client = BlobClient.from_blob_url(blob_url=a_blob_url + a_sas_key) if a_file_type == '.csv': qa_reader = blob_client.query_blob( a_query, blob_format=DelimitedTextDialect(has_header=True), encoding='utf-8') elif a_file_type == '.json': qa_reader = blob_client.query_blob( a_query, blob_format=DelimitedJsonDialect(delimeter=' '), encoding='utf-8', output_format=DelimitedJsonDialect(delimiter='\n')) elif a_file_type == '.parquet': qa_reader = None print("We'll do something about this") else: qa_reader = None print(f"Sorry, can't query a {a_file_type} file type") end = time.perf_counter() #Show (sarcastic voice) *usefully accurate* elapsed seconds and return records print(f"Time taken to get results {end - start} seconds") if qa_reader is None: print("No result found. Sorry human, better luck nextime ¯\_(ツ)_/¯") else: for row in qa_reader.records(): if row: result_set.append(row) return result_set
from matplotlib.figure import Figure from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar song_pool = ["/home/vex/Music", "."] curr_list = [ "example.flac", ] playlists = ["My First Playlist", "Awesome Mixtape", "Chill Ambience Tracks"] # Get files and folders for tgt in song_pool: print("In", tgt) for url, fldr, rsrc in fetch_dir(tgt): for r in rsrc: i, ext = get_ext(r) if ext[1:].upper() in sf.available_formats(): print("\t", url, "/", r) # Get Metadata mtdt = mt.File(curr_list[0]) print(mtdt.info.pprint()) print(mtdt.tags.pprint()) print(mtdt.pictures) # Play Audio data, srate = sf.read(curr_list[0], dtype='float32') comfirm = input("Play song? ") sd.play(data, srate) """ # Draw Spectrum
def solve_from_dirs(self): # fold_list = g.ListStore(str,str) # dir_list = g.ListStore(str,str) pool_list = g.ListStore(str, str, str, str, str, str, str, str) # Get files and folders for tgt in self.song_dirs: for url, fldr, rsrc in fetch_dir(tgt): for r in rsrc: i, ext = get_ext(r) place = url + "/" + r if ext[1:].upper() in formats: song = Song(place, self) self.mem_taken += basicsize(song) self.number_songs += 1 pool_list.append([ song.meta["title"], song.meta["author"], song.meta["album"], song.meta["year"], song.meta["genre"], song.meta["duration"], "0", place, ]) if ext[1:].upper() == "M3U": self.playlists[place] = g.ScrolledWindow() self.playlists[place].add( g.TreeView( g.ListStore(str, str, str, str, str, str, str, str))) tab_text = g.Label(i) tab_text.set_max_width_chars(8) self.playbook.prepend_page(self.playlists[place], tab_text) #self.playbook.set_tab_reorderable(tab_text, True) #self.playlists[place].get_children()[0].set_reorderable(True) self.playlists[place].get_children()[0].get_selection( ).set_mode(g.SelectionMode.MULTIPLE) self.playlists[place].get_children()[0].set_grid_lines( g.TreeViewGridLines.VERTICAL) self.playlists[place].get_children()[0].connect( "cursor_changed", self.songSelect) self.playlists[place].get_children()[0].connect( "row_activated", self.songSet) for i, col_title in enumerate([ "Nr.", "Title", "Author", "Album", "Year", "Genre", "Length", "Kudos" ]): rend = g.CellRendererText() col = g.TreeViewColumn(col_title, rend, text=i) #col.set_sort_column_id(i) col.set_reorderable(True) col.set_resizable(True) self.playlists[place].get_children( )[0].append_column(col) pool_view = g.TreeView(pool_list) pool_view.set_enable_search(True) pool_view.set_grid_lines(g.TreeViewGridLines.VERTICAL) pool_view.get_selection().set_mode(g.SelectionMode.MULTIPLE) #pool_view.connect("clicked", self.on_close_clicked) pool_view.connect("button-press-event", self.onClick) for i, col_title in enumerate([ "Title", "Author", "Album", "Year", "Genre", "Length", "Kudos", "Location", ]): rend = g.CellRendererText() col = g.TreeViewColumn(col_title, rend, text=i) col.set_sort_column_id(i) col.set_reorderable(True) col.set_resizable(True) pool_view.append_column(col) self.pool.add(pool_view)
def __init__(self, url, controller): """ «controller» is the object instance that controls the songs. Might be some "song_manager" class, but usually is the main GTK class. """ self.ui = controller self.url = os.path.realpath(url) if not os.path.isfile(self.url): print("File doesn't exist!") self.gsbin = gst.ElementFactory.make("playbin", None) gsnul = gst.ElementFactory.make("fakesink", "nulsnk") self.gsbin.set_property("video_sink", gsnul) self.gsbus = self.gsbin.get_bus() self.gsbus.connect("message", self.gstreamer_message) self.gsbus.add_signal_watch() self.gsbin.set_property("uri", "file://" + self.url) self.gsbin.set_state(gst.State.READY) #self.gsbin.volume = 0.5 self.raw_meta = mt.File(self.url) drctr, flnm = get_name(url) bsnm, ext = get_ext(flnm) secs = round(self.raw_meta.info.length, 2) mins = secs / 60 secs = int((mins % 1) * 60) mins = int(mins) hrs = mins / 60 mins = int((hrs % 1) * 60) hrs = int(hrs) duration = ":".join( (str(hrs).zfill(2), str(mins).zfill(2), str(secs).zfill(2))) self.meta = { "nanosecs": None, # Duration in nanosecs, to interface with GStreamer "duration": duration, # Duration, but in a human readable form. "number": "NaN", "title": bsnm, "author": "UNDEFINED", "album": "UNDEFINED", "year": "????", "genre": "UNDEFINED", "pics": dict(), "thumbnail": None, } for kind, each in { "number": ("tracknumber", "TRCK"), "title": ("title", "TIT2"), "author": ("artist", "albumartist", "album-artist", "TPE1", "performer", "composer"), "album": ("album", "TALB"), "year": ("date", "TDRC"), "genre": ("genre", "TCON"), }.items(): for variant in each: result = self.raw_meta.tags.get(variant, False) if result: if kind == "year": self.meta[kind] = str(result[0])[:4] elif kind == "number": self.meta[kind] = str(result[0]).zfill(3) else: self.meta[kind] = str(result[0]) break # Stop looking for it once a result was found. Thus the order of the options to try has a priority.