-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·58 lines (53 loc) · 1.82 KB
/
app.py
File metadata and controls
executable file
·58 lines (53 loc) · 1.82 KB
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
51
52
53
54
55
56
57
58
import math
import time
from flask import Flask, request, jsonify
from flask_cors import CORS
from reader import FileReader, Bolder
app = Flask(__name__)
CORS(app)
start_reading = time.time()
reader = FileReader('./data/IR-F19-Project01-Input.xlsx', True, './matches.json', './exceptions.txt')
# reader = FileReader('./data/IR-F19-Project01-Input-2k.xlsx', True, './matches.json', './exceptions.txt')
# reader = FileReader('./data/IR-F19-Project02-14k.csv', False, './matches.json', './exceptions.txt')
end_reading = time.time()
print("Reading Files:", end_reading - start_reading, "secs")
bolder = Bolder()
@app.route('/')
def query():
q = request.args.get('q')
start_searching = time.time()
print("Query:", q)
docs, query_tokens = reader.search(q, 50)
docs, query_tokens = list(docs), list(query_tokens)
print("Results:", len(docs))
items = int(request.args.get('items', 10))
print("Items:", items)
pages = math.ceil(len(docs) / items)
print("Pages:", pages)
page = int(request.args.get('page', 0))
print("Page:", page)
start = min(page * items, len(docs))
print("Start:", start)
end = min((page + 1) * items, len(docs))
print("End:", end)
articles = [{
'publish_date': doc.publish_date,
'title': str(doc.title),
'url': doc.url,
'summary': bolder.bold(str(doc.summary), query_tokens),
'meta_tags': doc.meta_tags,
'content': bolder.bold(str(doc.content), query_tokens),
'thumbnail': str(doc.thumbnail),
} for doc in docs[start:end]]
end_searching = time.time()
print('Search Time:', end_searching - start_searching, "secs")
print()
return jsonify({
"query": q,
"items": items,
"pages": pages,
"page": page,
"articles": articles,
})
if __name__ == '__main__':
app.run()