forked from wragge/ww1-records-finder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwwifinder.py
More file actions
104 lines (78 loc) · 2.63 KB
/
wwifinder.py
File metadata and controls
104 lines (78 loc) · 2.63 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import urllib
import re
from flask import Flask
from flask import render_template
from flask import request, jsonify
from rstools.client import RSSearchClient, RSItemClient
from cwgctools.client import CWGCClient
from awmtools.client import AWMBioSearchClient, RollClient, EmbarkationClient, RedCrossClient, HonoursClient
CONTEXT = 'local'
#CONTEXT = 'production'
app = Flask(__name__)
class WebFactionMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
environ['SCRIPT_NAME'] = '/ww1-records'
return self.app(environ, start_response)
if CONTEXT == 'production':
app.wsgi_app = WebFactionMiddleware(app.wsgi_app)
@app.route('/')
def show_index():
return render_template('index.html')
@app.route('/naa/search/')
def search_naa():
rs = RSSearchClient()
kwargs = request.args.to_dict()
kwargs['page'] = request.args.get('page', 1)
kwargs['sort'] = 3
print kwargs
results = rs.search_names(**kwargs)
return jsonify(results)
@app.route('/naa/items/<barcode>/')
def get_naa_item(barcode):
rs = RSItemClient()
result = rs.get_summary(barcode, date_format='iso')
return jsonify({'result': result})
@app.route('/cwgc/search/')
def search_cwgc():
wgc = CWGCClient()
kwargs = request.args.to_dict()
kwargs['australian'] = ['on']
kwargs['war'] = ['First World War']
kwargs['forename_initials'] = ['rdoForename']
results = wgc.search(**kwargs)
return jsonify(results)
@app.route('/cwgc/items/<path:url>/')
def get_cwgc_item(url):
url = url.replace(' ', '%20')
url = url.replace('http:/w', 'http://w')
cwgc = CWGCClient()
result = cwgc.get_details(url)
return jsonify({'result': result})
@app.route('/awm/<path:db>/search/')
def search_awm_dbs(db):
awm = AWMBioSearchClient()
kwargs = request.args.to_dict()
kwargs['db'] = db
if db == 'honours_and_awards':
kwargs['roll_type'] = 'All'
kwargs['conflict'] = 'First World War, 1914-1918'
results = awm.search(**kwargs)
return jsonify(results)
@app.route('/awm/items/<path:roll>/<path:url>')
def get_awm_item(roll, url):
url = re.sub(r'person\.asp\/', 'person.asp?p=', url)
url = url.replace('http:/w', 'http://w')
if 'roll_of_honour' in roll:
awm = RollClient()
elif 'embarkation' in roll:
awm = EmbarkationClient()
elif 'wounded_and_missing' in roll:
awm = RedCrossClient()
elif 'honours_and_awards' in roll:
awm = HonoursClient()
result = awm.get_details(url=url)
return jsonify({'result': result})
if __name__ == '__main__':
app.run(debug=True)