-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
50 lines (40 loc) · 1.34 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import re
from flask import Flask, render_template, request, redirect
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
from nltk.stem import PorterStemmer
import nltk
nltk.download('punkt')
# Use a service account
cred = credentials.Certificate('boilermake-8-project-firebase-adminsdk-n45vg-c326d22181.json')
firebase_admin.initialize_app(cred)
db = firestore.client()
query_ref = db.collection(u'profdata')
app = Flask(__name__)
returnData = {}
def process(s):
# converts to lowercase
s = s.lower()
# removes punctuation
s = re.sub(r'[^\w\s]', '', s)
# converts words to root words (stemming)
porter = PorterStemmer()
s = " ".join([porter.stem(word) for word in nltk.tokenize.word_tokenize(s)])
return s
@app.route('/', methods = ['GET'])
def default():
return render_template('index.html')
@app.route('/results')
def results():
return render_template('results.html', data = returnData);
@app.route('/', methods = ['POST'])
def retrieve():
returnData.clear()
docs = db.collection(u'profdata').stream()
for doc in docs:
if (u'researchArea' in doc.to_dict() and process(request.form[u'area']) in doc.to_dict()[u'researchArea']):
returnData[doc.id] = doc.to_dict()
return redirect('/results')
if __name__ == '__main__':
app.run(debug=True)