<commit_before># might need to look at this sometime: http://markjberger.com/flask-with-virtualenv-uwsgi-nginx/
from flask import Flask, render_template, request, json
import os, thread
import powertoken, weconnect

# Creates a new Flask server application
app = Flask(__name__)

# We will use the powertoken object to access the core PowerToken functions.
powertoken = powertoken.PowerToken()

# Stores the user's email (for referencing the tinydb) across the session
email = ""

# THE LANDING PAGE
@app.route('/')
@app.route('/home')
def home():
	return render_template('home.html')

# WECONNECT FORM SUBMIT, FITBIT REDIRECT
@app.route('/login', methods=['GET', 'POST'])
def login():
	# WEconnect form submit uses POST
	if request.method == 'POST':
		received = request.form

		# If user is already logged in, tells him/her so
		if powertoken.isLoggedIntoWc(request.form["name"]):
			return render_template('home.html', wc_response="You are already logged into WEconnect.")

		# Logs user into WEconnect if he/she isn't already
		powertoken.loginToWc(request.form["name"], request.form["psk"])
		email = request.form["name"]

		return render_template('home.html', wc_response="Login successful")

	# Fitbit redirect uses GET
	elif request.method == 'GET':
		return render_template('login.html')

# The callback for Fitbit API (http://host-url/fb_login). 
# Note: login.html contains JavaScript
@app.route('/fb_login', methods=['GET'])
def fb_login():
	# First, sees if the user is already logged into Fitbit
	if powertoken.isLoggedIntoFb(email):
		return render_template('home.html', fb_response="You are already logged into Fitbit.")

	# If not, logs in and stores access token
	else:
		return render_template('login.html')

# When Fitbit is all setup, login.html redirects to here
@app.route('/result', methods=['GET', 'POST'])
def result():
	data = request.data
	convData = data.decode('utf8')
	datajs = json.loads(convData)

	# Stores access token in a JSON file
	#jsonStr = '{"userToken":"' + datajs["tok"] + '"}'
	#with open("data/fb.json", "w+") as file:
	#	file.write(jsonStr)

	powertoken.completeFbLogin(email, datajs["tok"])
	
	return render_template('home.html', fb_response="Login successful")

@app.route('/start', methods=['GET', 'POST'])
def start():
	thisEmail = ""
	if request.method == 'GET':
		thisEmail = email
	elif request.method == 'POST':
		thisEmail = request.form["email"]
	thread.start_new_thread(render_template, ('running.html'))
	thread.start_new_thread(powertoken.startExperiment, (thisEmail))

@app.route('/test', methods=['GET', 'POST'])
def test():
	powertoken.runTests()
	#data = request.data
	return render_template('home.html')

if __name__ == "__main__":
	app.run(debug=False)<commit_msg>Turns out I need a comma in a tuple with one object<commit_after># might need to look at this sometime: http://markjberger.com/flask-with-virtualenv-uwsgi-nginx/
from flask import Flask, render_template, request, json
import os, thread
import powertoken, weconnect

# Creates a new Flask server application
app = Flask(__name__)

# We will use the powertoken object to access the core PowerToken functions.
powertoken = powertoken.PowerToken()

# Stores the user's email (for referencing the tinydb) across the session
email = ""

# THE LANDING PAGE
@app.route('/')
@app.route('/home')
def home():
	return render_template('home.html')

# WECONNECT FORM SUBMIT, FITBIT REDIRECT
@app.route('/login', methods=['GET', 'POST'])
def login():
	# WEconnect form submit uses POST
	if request.method == 'POST':
		received = request.form

		# If user is already logged in, tells him/her so
		if powertoken.isLoggedIntoWc(request.form["name"]):
			return render_template('home.html', wc_response="You are already logged into WEconnect.")

		# Logs user into WEconnect if he/she isn't already
		powertoken.loginToWc(request.form["name"], request.form["psk"])
		email = request.form["name"]

		return render_template('home.html', wc_response="Login successful")

	# Fitbit redirect uses GET
	elif request.method == 'GET':
		return render_template('login.html')

# The callback for Fitbit API (http://host-url/fb_login). 
# Note: login.html contains JavaScript
@app.route('/fb_login', methods=['GET'])
def fb_login():
	# First, sees if the user is already logged into Fitbit
	if powertoken.isLoggedIntoFb(email):
		return render_template('home.html', fb_response="You are already logged into Fitbit.")

	# If not, logs in and stores access token
	else:
		return render_template('login.html')

# When Fitbit is all setup, login.html redirects to here
@app.route('/result', methods=['GET', 'POST'])
def result():
	data = request.data
	convData = data.decode('utf8')
	datajs = json.loads(convData)

	# Stores access token in a JSON file
	#jsonStr = '{"userToken":"' + datajs["tok"] + '"}'
	#with open("data/fb.json", "w+") as file:
	#	file.write(jsonStr)

	powertoken.completeFbLogin(email, datajs["tok"])
	
	return render_template('home.html', fb_response="Login successful")

@app.route('/start', methods=['GET', 'POST'])
def start():
	thisEmail = ""
	if request.method == 'GET':
		thisEmail = email
	elif request.method == 'POST':
		thisEmail = request.form["email"]
	thread.start_new_thread(render_template, ('running.html',)) # the comma is NOT an error
	thread.start_new_thread(powertoken.startExperiment, (thisEmail,))

@app.route('/test', methods=['GET', 'POST'])
def test():
	powertoken.runTests()
	#data = request.data
	return render_template('home.html')

if __name__ == "__main__":
	app.run(debug=False)
{'fraction_non_alphanumeric': 0.14205573651827724, 'fraction_numerical': 0.0003619254433586681, 'mean_word_length': 5.245197740112994, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1025517', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1768, 'n_words': 516}