#NEWLINE# def get_album_dict( db_session , artist_id = None ) : #NEWLINE# #INDENT# 'Returns a dictionary of all the albums from an artist from the database\n    This will check to see if the info exists locally before querying Ampache.' #NEWLINE# album_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( artist_id is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# c = db_session . cursor ( ) #NEWLINE# c . execute ( 'SELECT album_id, name, year, precise_rating FROM albums' ) #NEWLINE# for row in c : #NEWLINE# #INDENT# album_id = row [ 0 ] #NEWLINE# album_name = row [ 1 ] #NEWLINE# album_year = row [ 2 ] #NEWLINE# precise_rating = row [ 3 ] #NEWLINE# album_dict [ album_id ] = { #NEWLINE# #INDENT# 'name' : album_name , #NEWLINE# 'year' : album_year , #NEWLINE# 'precise_rating' : precise_rating , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# album_dict = None #NEWLINE# #UNINDENT# c . close ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# c = db_session . cursor ( ) #NEWLINE# c . execute ( 'SELECT album_id, name, year, precise_rating FROM albums\n                WHERE artist_id = ? order by year' , [ artist_id ] ) #NEWLINE# for row in c : #NEWLINE# #INDENT# album_id = album_year [ 0 ] #NEWLINE# album_name = row [ 1 ] #NEWLINE# album_year = row [ 2 ] #NEWLINE# precise_rating = row [ 3 ] #NEWLINE# album_dict [ album_id ] = { #NEWLINE# #INDENT# 'name' : album_name , #NEWLINE# 'year' : album_year , #NEWLINE# 'precise_rating' : precise_rating , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# album_dict = None #NEWLINE# #UNINDENT# c . close ( ) #NEWLINE# #UNINDENT# return album_dict