from flask import Flask, request, redirect, render_template from parsers.CSV_to_RDF_Autori import parse, parsefromfile import yaml app = Flask(__name__) @app.route('/', methods=['POST','GET']) def ciapatelaforma(): if request.method == 'POST': fileFromRequest = request.files['FILE'] filename = fileFromRequest.filename if filename != '': outFileName = fileFromRequest.filename.replace('.csv', '') + '.ttl' file1 = fileFromRequest.read() # try to create list of dictionaries keyed by header row parsefromfile(file1, outFileName) else: # Da completare paglia = {} paglia['AUTN'] = request.form['AUTN'] paglia['AUTL'] = request.form['AUTL'] paglia['AUTD'] = request.form['AUTD'] paglia['TSK'] = '' paglia['ESC'] = '' paglia['URL'] = '' paglia['AUTA'] = '' paglia['AUTC'] = '' paglia['AUTO'] = '' paglia['AUTV'] = '' paglia['AUTZ'] = '' paglia['AUTX'] = '' paglia['AUTT'] = '' paglia['AUTU'] = '' paglia['AUTQ'] = '' paglia['AUTH'] = '' paglia['CMPD'] = '' paglia['CMPN'] = '' paglia['RSR'] = '' paglia['FUR'] = '' check = [val for key, val in paglia.items() if val!=''] if len(check)>0: parse([paglia], 'form_output.ttl') else: return redirect('/error/') return redirect('/') return render_template('index.html') @app.route('/error/', methods=['POST','GET']) def error(): if request.method == 'POST': return redirect('/') else: return render_template('error.html') if __name__ == '__main__': app.run()