import redcap2nacc_flask
import argparse
import os

from flask import Flask, render_template, request, redirect, url_for

#which one?
from werkzeug.utils import secure_filename
from werkzeug import secure_filename

UPLOAD_FOLDER = '/path/to/the/uploads'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER





app = Flask(__name__)
email_addresses = []
redcapWarnings = []

@app.route('/')
def hello_world():
    author = "Zac"
    name = "Sean and Zac"
    return render_template('index.html', author=author, name=name)
    
# @app.route('/upload')
# def upload_file():
   # return render_template('upload.html')    

@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
   if request.method == 'POST':
      f = request.files['file']
      f.save(secure_filename(f.filename))
      # print(f)
      # print(secure_filename(f.filename))
      # cwd = os.getcwd() # working directory is where the python code is
      # print(cwd)
      # redcap2nacc.main(f.filename)
      # redcapWarnings = redcap2nacc_flask.main(f.filename)
      # print (redcap2nacc_flask.main(f.filename))
      redcapWarnings.append(redcap2nacc_flask.main(f.filename))
      return 'file uploaded successfully, Nacc form converted. Please check /warnings.html for conversion warnings.'+ "\n" + 'Find the converted file: ' + 'NaccConverted_' + f.filename[:-4] + '.txt'

@app.route('/signup', methods = ['POST'])
def signup():
    email = request.form['email']
    email_addresses.append(email)
    print(email_addresses) 
    print("The email address is '" + email + "'")
    return redirect('/')

@app.route('/warnings.html')
def warning():
    return render_template('warnings.html', warnings=redcapWarnings)
	
@app.route('/emails.html')
def emails():
    return render_template('emails.html', email_addresses=email_addresses)
	
if __name__ == '__main__':
    #Call nacculator and process data uploaded from user
    
		# raw_csv = argparse.ArgumentParser(description='Process redcap form output to nacculator.')
    
    app.run()
@@ -386,16 +386,17 @@
 OLDER%0A%0A%0A
+ 
 %0A%0A%0Aapp =
@@ -601,20 +601,16 @@
 e=name)%0A
-    
 %0A# @app.
@@ -689,20 +689,16 @@
 d.html')
-    
 %0A%0A@app.r
@@ -1582,18 +1582,17 @@
 dresses)
- 
 %0A
+
     prin
@@ -1772,18 +1772,17 @@
 rnings)%0A
-%09
 %0A
+
 @app.rou
@@ -1893,10 +1893,9 @@
 es)%0A
-%09
 %0A
+
 if _
@@ -1974,21 +1974,17 @@
 om user%0A
-    
 %0A
+
 %09%09# raw_
@@ -2070,20 +2070,16 @@
 ator.')%0A
-    
 %0A    app
@@ -2084,8 +2084,9 @@
 pp.run()
+%0A

test to delete