-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.py
242 lines (212 loc) · 7.84 KB
/
api.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import flask
import re
from flask import request, jsonify
from test_queries import *
from netapp_test2 import *
from mySummarizer import *
from finaldetails import *
from flask import Flask, send_file, render_template
app = flask.Flask(__name__)
app.config["DEBUG"] = True
class DataStore():
det=[]
data=DataStore()
@app.route('/advSearch', methods=['GET'])
def api_search1():
return render_template("advSearch.html")
@app.route('/about', methods=['GET'])
def api_about():
return render_template("about.html")
@app.route('/', methods=['GET'])
def api_home():
return render_template('home.html')
@app.route('/askquery', methods=['GET'])
def api_query():
text1=""
text2=""
if 'query' in request.args:
ret=test_query(request.args['query'])
fin=[]
flag=0
if 'date' in request.args:
for i in ret:
match=re.search(r'\d+', i)
name=match.group()
if (retrieve_firstdate(name)==request.args['date']):
fin.append(i)
if(request.args['date']):
flag=1
if 'appeal_no' in request.args:
for i in ret:
match=re.search(r'\d+', i)
name=match.group()
appellate_jurisdiction, appeal_num=retrieve_AppellateJurisdiction(name)
if (appeal_num==request.args['appeal_no']):
fin.append(i)
if(request.args['appeal_no']):
flag=1
if 'appellate' in request.args:
ret1=request.args['appellate']
ret1=ret1.lower()
for i in ret:
match=re.search(r'\d+', i)
name=match.group()
appellate_jurisdiction, appeal_num=retrieve_AppellateJurisdiction(name)
if(appellate_jurisdiction):
if (appellate_jurisdiction.lower()==ret1):
fin.append(i)
if(request.args['appellate']):
flag=1
if flag!=1:
fin=ret
if len(fin)==0:
text1= "No relevant document found."
else:
text2= "Error: No query provided. Please specify query."
cleanlist=[]
[cleanlist.append(x) for x in fin if x not in cleanlist]
fin=cleanlist
det2=[]
count_file=1
for filename in fin:
if (re.search(r'\d+', filename)):
det2.append(getdetails(filename,count_file))
count_file+=1
while(len(det2)<10):
det2.append(("","","","","","",""))
data.det=det2
return render_template("searchResults.html",text1=text1,text2=text2,det=det2)
@app.route('/docwise')
def api_docwise():
try:
if 'document' in request.args:
ret=retrieve_finalJudgement((request.args.get('document', 0, type=str)).zfill(4))
if ret is None:
return jsonify(result="Error: Could not retrieve data for the specified document.")
else:
return jsonify(result="Error: No document number provided. Please specify.")
return jsonify(result=ret)
except Exception as e:
return str(e)
@app.route('/docwise2')
def api_docwise2():
try:
if 'document' in request.args:
pc=retrieve_penalCodes((request.args.get('document', 0, type=str)).zfill(4))
ret=[]
if pc is None:
return jsonify(result="Error: Could not retrieve data for the specified document.")
for ipc, codename in pc:
ret.append(" "+codename+" "+ipc)
if len(ret) is 0:
return jsonify(result="There are no Penal Codes in this document.")
else:
return jsonify(result="Error: No document number provided. Please specify.")
if len(ret) is 0:
return jsonify(result="There are no Penal Codes in this document.")
return jsonify(result=ret)
except Exception as e:
return str(e)
@app.route('/docwise3')
def api_docwise3():
try:
if 'document' in request.args:
ret=retrieve_firstdate((request.args.get('document', 0, type=str)).zfill(4))
if ret is None:
return jsonify(result="Error: Could not retrieve data for the specified document.")
else:
return jsonify(result="Error: No document number provided. Please specify.")
return jsonify(result=ret)
except Exception as e:
return str(e)
@app.route('/docwise4')
def api_docwise4():
try:
if 'document' in request.args:
ret=retrieve_AppellateJurisdiction((request.args.get('document', 0, type=str)).zfill(4))
if ret[0] is None:
return jsonify(result="This document does not contain an appellate jurisdiction.")
else:
return jsonify(result="Error: No document number provided. Please specify.")
return jsonify(result=ret)
except Exception as e:
return str(e)
@app.route('/download')
def download_file():
if 'doc' in request.args:
fileno=request.args['doc'].zfill(4)
path = "Prior_Cases/prior_case_"+fileno+'.txt'
else:
return "Enter document name."
return send_file(path, as_attachment=True)
@app.route('/download1')
def download1_file():
if 'doc' in request.args:
if request.args['doc'] == "det00":
filename=data.det[0][5]
elif request.args['doc'] == "det10":
filename=data.det[1][5]
elif request.args['doc'] == "det20":
filename=data.det[2][5]
elif request.args['doc'] == "det30":
filename=data.det[3][5]
elif request.args['doc'] == "det40":
filename=data.det[4][5]
elif request.args['doc'] == "det50":
filename=data.det[5][5]
elif request.args['doc'] == "det60":
filename=data.det[6][5]
elif request.args['doc'] == "det70":
filename=data.det[7][5]
elif request.args['doc'] == "det80":
filename=data.det[8][5]
elif request.args['doc'] == "det90":
filename=data.det[9][5]
path = "Prior_Cases/"+filename
else:
return "Invalid Link"
return send_file(path, as_attachment=True)
@app.route('/background_process')
def background_process():
try:
if 'query' in request.args:
ret=test_query(request.args['query'])
fin=[]
flag=0
if 'date' in request.args:
for i in ret:
if (retrieve_firstdate(i)==request.args['date']):
fin.append(i)
print(i)
if(request.args['date']):
flag=1
if 'appeal_no' in request.args:
for i in ret:
appellate_jurisdiction, appeal_num=retrieve_AppellateJurisdiction(i)
if (appeal_num==request.args['appeal_no']):
fin.append(i)
if(request.args['appeal_no']):
flag=1
if 'appellate' in request.args:
ret1=request.args['appellate']
ret1=ret1.lower()
for i in ret:
appellate_jurisdiction, appeal_num=retrieve_AppellateJurisdiction(i)
if(appellate_jurisdiction):
if (appellate_jurisdiction.lower()==ret1):
fin.append(i)
if(request.args['appellate']):
flag=1
if flag!=1:
fin=ret
else:
fin.append( "Error: No query provided. Please specify query.")
cleanlist=[]
[cleanlist.append(x) for x in fin if x not in cleanlist]
fin=cleanlist
for i in range (len(fin),10):
fin.append(" ")
return jsonify(result = fin)
except Exception as e:
return str(e)
app.run()