Commit 02335613 authored by Akshay Karthik's avatar Akshay Karthik
Browse files

initial commit

parents
* text=auto
.DS_Store
*~
*.pyc
.sass-cache
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def base_api():
return 'Peoplefinder Api'
@app.route('/all')
def search_all():
return ''
@app.route('/students')
def search_students():
return ''
@app.route('/faculty')
def search_faculty():
return ''
import re
import requests
from bs4 import BeautifulSoup
BASE_URL = "http://peoplefinder.gmu.edu/index.php"
MODE = {
"standard": "mode=standard",
"advanced": "mode=advanced"
}
def call_standard(search, group="all", page=1):
url = "{base}?search={search}&group={group}&people=100".format(
base=BASE_URL,
search=search,
group=group)
url += "&page={page}".format(page=page)
current_page = requests.get(url)
soup = BeautifulSoup(current_page.content)
people = []
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}
for attribute in person:
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':
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
people.append(current_result)
return {
'results': people,
'hasNextPage': bool(soup.find('li', {'class': 'next'}))
}
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.9.6
argparse==1.2.1
beautifulsoup4==4.3.2
itsdangerous==0.24
requests==2.5.1
wsgiref==0.1.2
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