<s> import base64 <EOL> from os import listdir <EOL> from os . path import isfile , dirname , realpath , join <EOL> import subprocess <EOL> from flask import url_for <EOL> import collections <EOL> epub_directory_path = "<STR_LIT>" <EOL> static_path = dirname ( realpath ( __file__ ) ) + "<STR_LIT>" <EOL> def convert_ebook ( input_name ) : <EOL> output_name = input_name . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if isfile ( static_path + output_name ) : <EOL> return url_for ( '<STR_LIT>' , filename = output_name ) <EOL> process = subprocess . Popen ( [ '<STR_LIT>' , epub_directory_path + input_name , static_path + output_name ] , stdout = subprocess . PIPE ) <EOL> process . wait ( ) <EOL> return url_for ( '<STR_LIT>' , filename = output_name ) <EOL> def create_link ( ebook_name ) : <EOL> encoded = str_to_base64 ( ebook_name ) <EOL> return "<STR_LIT>" + encoded <EOL> def get_epubs ( path , keyword ) : <EOL> return [ f for f in listdir ( path ) if isfile ( join ( path , f ) ) and f [ - <NUM_LIT:4> : ] == "<STR_LIT>" and keyword in f ] <EOL> def str_to_base64 ( s ) : <EOL> return base64 . b64encode ( s . encode ( '<STR_LIT:utf-8>' ) ) . decode ( "<STR_LIT:utf-8>" ) <EOL> def base64_to_str ( b ) : <EOL> return base64 . b64decode ( b . encode ( '<STR_LIT:utf-8>' ) ) . decode ( '<STR_LIT:utf-8>' ) <EOL> def group_results ( results ) : <EOL> groups = collections . defaultdict ( list ) <EOL> for result in results : <EOL> groups [ result [ "<STR_LIT:name>" ] [ <NUM_LIT:0> ] ] . append ( result ) <EOL> return collections . OrderedDict ( sorted ( groups . items ( ) ) ) . items ( ) </s>
