Beispiel #1
0
def register():
	db = DBConnection()
	d = request.args
	params = {k:v for k,v in d.iteritems()}
	params['gender'] = params.pop('gensel')
	params['driver'] = True if params.pop('dsel') is 'y' else False
	params['graduating'] = True if params.pop('gsel') is 'y' else False
	params['shirt'] = params.pop('ssel')
	params['gym'] = params.pop('msel')
	if len(db.get('members', fname=params['fname'], lname=params['lname'])) == 0:
		db.insert('members',timestamp=datetime.datetime.utcnow(),**params)
		return jsonify(already_inserted='false')
	else:
		return jsonify(already_inserted='true')
Beispiel #2
0
def register():
    db = DBConnection()
    d = request.args
    params = {k: v for k, v in d.iteritems()}
    params['gender'] = params.pop('gensel')
    params['driver'] = True if params.pop('dsel') is 'y' else False
    params['graduating'] = True if params.pop('gsel') is 'y' else False
    params['shirt'] = params.pop('ssel')
    params['gym'] = params.pop('msel')
    if len(db.get('members', fname=params['fname'],
                  lname=params['lname'])) == 0:
        db.insert('members', timestamp=datetime.datetime.utcnow(), **params)
        return jsonify(already_inserted='false')
    else:
        return jsonify(already_inserted='true')
Beispiel #3
0
def populate_class():
	db = DBConnection()
	name = request.args.get("name","")
	links = [x['link'] for x in db.get("classes", Instructor=name)]
	for link in links:
		r = requests.get(link)
		soup = BeautifulSoup(r.content)
		print "processed, %s" % (r.status_code) 
		rows = list(soup.find_all('tr'))[1:]
		rowdict = {}
		for row in rows[1:]:
			row = filter(lambda x: x != '\n', row)
			if len(row) == 2:
				rowdict.update({row[0].get_text().strip() : row[1].get_text().strip()})
		print rowdict
		db.update("classes", {'Instructor': name, 'link':link},**rowdict)

	return jsonify(links=links)
Beispiel #4
0
def search_for_prof():
	db = DBConnection()
	name = request.args.get("name","")
	classes = db.classes_for_name(name)
	if classes is not None:
		return jsonify(name=name, classes=classes)
	params = {
			  "q" : name, 
			  "site" : "Directory_of_Classes", 
			  "num" : 20, 
			  "filter" : 0,
			  "entqr" : 0, 
			  "ud" : 1,
			  "sort" : "date%3AD%3AL%3Ad1", 
			  "output" : "xml_no_dtd",
			  "oe" : "UTF-8",
			  "ie" : "UTF-8",
			  "client" : "DoC",
			  "proxystylesheet" : "DoC",
			  "proxyreload" : 1
			 }
	search = requests.get("http://search.columbia.edu/search", params=params)
	search_result = BeautifulSoup(search.content)
	if search_result.find(id="empty") is None:
		classes = []
		for cls in search_result.find_all("a","l"):
			if "Fall 2012" in "".join(map(str, cls.contents)):
				x = cls.get('href')
				classes.append(x)
				db.insert('classes', Instructor = name, link=x)
		return jsonify(name=name, classes=classes)
	db.insert('classes', Instructor = name, no_classes=True)
	return jsonify(name=name, classes=[])
Beispiel #5
0
def index():
    db = DBConnection()
    num_members = db.get('members', gym='mphc')
    if len(num_members) >= 50:
        return render_template('index.html', mphc_available=False)
    return render_template('index.html', mphc_available=True)
Beispiel #6
0
def index():
	db = DBConnection()
	num_members = db.get('members',gym='mphc')
	if len(num_members) >= 50:
		return render_template('index.html', mphc_available=False)
	return render_template('index.html', mphc_available=True)