app.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from flask import Flask, request, redirect, render_template
  2. from parsers.CSV_to_RDF_Autori import parse, parsefromfile
  3. import yaml
  4. app = Flask(__name__)
  5. @app.route('/', methods=['POST','GET'])
  6. def ciapatelaforma():
  7. if request.method == 'POST':
  8. fileFromRequest = request.files['FILE']
  9. filename = fileFromRequest.filename
  10. if filename != '':
  11. outFileName = fileFromRequest.filename.replace('.csv', '') + '.ttl'
  12. file1 = fileFromRequest.read()
  13. # try to create list of dictionaries keyed by header row
  14. parsefromfile(file1, outFileName)
  15. else:
  16. # Da completare
  17. paglia = {}
  18. paglia['AUTN'] = request.form['AUTN']
  19. paglia['AUTL'] = request.form['AUTL']
  20. paglia['AUTD'] = request.form['AUTD']
  21. paglia['TSK'] = ''
  22. paglia['ESC'] = ''
  23. paglia['URL'] = ''
  24. paglia['AUTA'] = ''
  25. paglia['AUTC'] = ''
  26. paglia['AUTO'] = ''
  27. paglia['AUTV'] = ''
  28. paglia['AUTZ'] = ''
  29. paglia['AUTX'] = ''
  30. paglia['AUTT'] = ''
  31. paglia['AUTU'] = ''
  32. paglia['AUTQ'] = ''
  33. paglia['AUTH'] = ''
  34. paglia['CMPD'] = ''
  35. paglia['CMPN'] = ''
  36. paglia['RSR'] = ''
  37. paglia['FUR'] = ''
  38. check = [val for key, val in paglia.items() if val!='']
  39. if len(check)>0:
  40. parse([paglia], 'form_output.ttl')
  41. else:
  42. return redirect('/error/')
  43. return redirect('/')
  44. return render_template('index.html')
  45. @app.route('/error/', methods=['POST','GET'])
  46. def error():
  47. if request.method == 'POST':
  48. return redirect('/')
  49. else:
  50. return render_template('error.html')
  51. if __name__ == '__main__':
  52. app.run()