import os
import requests
from flask import Flask, request, jsonify, redirect
from bs4 import BeautifulSoup

app = Flask(__name__)
app.debug = True

@app.route('/')
def index():
	return redirect("http://freeslugs.github.io/uniatcu/", code=302)

@app.route('/info')
def main():
	uni = request.args.get('uni')
	person = dict()

	if not uni:
		return error("please enter uni")
		
	
	elif len(uni) < 6:
		return error("length is too short")		

	else:
		r = requests.get('https://directory.columbia.edu/people/uni?code=' + uni)
		soup = BeautifulSoup(r.text)
		tds = soup.find('div', class_ = 'table_results_indiv').find('tbody').find_all('tr')
		
		for i in range(0,len(tds)):
			td = tds[i]
			if i == 0:
				if len(td.text) < 1:
					return error("person not found")
				else:
					person['name'] = td.text

			for j in range(0, len(td.contents)/2):
				left = td.contents[j*2].text.lower()
				right = td.contents[j*2+1].text.lower()
				left = left.replace(":", "")
				right = right.replace(":", "")
				if left and right and left != u"\u00a0" and right != u"\u00a0":
					person[left] = right

			i += 1
		return jsonify({"data": person}) 

if __name__ == '__main__':
	app.run()


def error(error="unknown error has occured"):
	return jsonify({"error": error})
@@ -1140,46 +1140,373 @@
 ) %0A%0A
-if __name__ == '__main__':%0A%09app.run()%0A
+@app.route('/exists')%0Adef exist():%0A%09uni = request.args.get('uni')%0A%0A%09if not uni:%0A%09%09return error(%22please enter uni%22)%0A%0A%09elif len(uni) %3C 6:%0A%09%09return error(%22length is too short%22)%0A%0A%09else:%0A%09%09r = requests.get('https://directory.columbia.edu/people/uni?code=' + uni)%0A%09%09if uni in r.text:%0A%09%09%09return jsonify(%7B%22exists%22: %22true%22%7D) %0A%09%09else: %0A%09%09%09return jsonify(%7B%22exists%22: %22false%22%7D) 
 %0A%0Ade
@@ -1582,8 +1582,48 @@
  error%7D)
+%0A%0A%0Aif __name__ == '__main__':%0A%09app.run()

exists fn