Commit 26039fcf authored by Akshay Karthik's avatar Akshay Karthik
Browse files

added actual flask

parent 02335613
from flask import Flask, jsonify
from peoplefinder import call_standard
app = Flask(__name__)
......@@ -6,16 +7,23 @@ app = Flask(__name__)
def base_api():
return 'Peoplefinder Api'
@app.route('/all')
def search_all():
return ''
@app.route('/all/<search>')
def search_all(search):
return jsonify(call_standard(search))
@app.route('/students')
def search_students():
return ''
@app.route('/students/<search>')
def search_students(search):
return jsonify(call_standard(search, group="students"))
@app.route('/faculty/<search>')
def search_faculty(search):
return jsonify(call_standard(search, group="students"))
@app.route('/faculty')
def search_faculty():
return ''
if __name__ == "__main__":
import os
app.run(
host=os.environ.get("HOST", "0.0.0.0"),
port=int(os.environ.get("PORT", "8080")),
debug=bool(os.environ.get("DEBUG"))
)
......@@ -23,29 +23,30 @@ def call_standard(search, group="all", page=1):
container_divs = soup.findAll('div', {'class': 'person'})
people_divs = map(lambda x: list(x.children), container_divs)
for person in people_divs:
current_result = {'type': None}
current_result = {"raw":[]}
for attribute in person:
current_result['raw'].append(str(attribute))
if attribute.name == 'h3':
current_result['name'] = attribute.text
elif attribute.name == 'p' and current_result['type'] is None:
content = attribute.text
re_match = re.match("Major: (.*)", content)
if re_match:
current_result['type'] = "Student"
current_result['major'] = re_match.group(1)
else:
current_result['type'] = "Faculty"
current_result['title'] = content
elif attribute.name == 'p':
content = attribute.text
major_match = re.match("Major: (.*)", content)
if major_match:
current_result['major'] = major_match.group(1)
email_match = re.match("Email: (.*)", content)
if email_match:
current_result['email'] = email_match.group(1)
if attribute.acronym:
current_result['address'] = attribute.text
elif attribute.span:
phone = attribute.find('span', {'class': 'phone'})
current_result['phone'] = phone.text if phone else None
fax = attribute.find('span', {'class': 'fax'})
current_result['fax'] = fax.text if fax else None
# comment the line below to debug
del current_result["raw"]
people.append(current_result)
return {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment