#NEWLINE# @ app . route ( '/api' , methods = [ 'GET' ] ) #NEWLINE# def data( ) : #NEWLINE# #INDENT# metric = request . args . get ( 'metric' , None ) #NEWLINE# try : #NEWLINE# #INDENT# raw_series = REDIS_CONN . get ( metric ) #NEWLINE# if ( not raw_series ) : #NEWLINE# #INDENT# resp = json . dumps ( { #NEWLINE# #INDENT# 'results' : 'Error: No metric by that name' , #NEWLINE# #UNINDENT# } ) #NEWLINE# return ( resp , 404 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# unpacker = Unpacker ( use_list = False ) #NEWLINE# unpacker . feed ( raw_series ) #NEWLINE# timeseries = [ item [ : 2 ] for item in unpacker ] #NEWLINE# resp = json . dumps ( { #NEWLINE# #INDENT# 'results' : timeseries , #NEWLINE# #UNINDENT# } ) #NEWLINE# return ( resp , 200 ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# error = ( 'Error: ' + e ) #NEWLINE# resp = json . dumps ( { #NEWLINE# #INDENT# 'results' : error , #NEWLINE# #UNINDENT# } ) #NEWLINE# return ( resp , 500 )