-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathutils.py
272 lines (237 loc) · 6.74 KB
/
utils.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# -*- coding: utf-8 -*-
from flask import Blueprint, current_app, request
import os
import json
import datetime
import platform
import csv
import os
import traceback
import yaml
import xmltodict
import json
from const import *
from tools import *
data = Blueprint('register', __name__)
@data.route('/json_test')
def json_test():
path = os.path.join("/root/api-server/", "test.json")
return json_helper(path)
@data.route('/xml_test')
def xml_test():
path = os.path.join("/root/api-server/", "test.xml")
return xml_helper(path)
@data.route('/hospital_list')
def hospital_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
hosptials_data = csv_with_medical_supplier(current_app.config['HOSPITAL_PATH'], HOSPITAL_HEADERS)
if 'limit' in request.args or 'skip' in request.args:
skip = request.args.get('skip', type=int)
limit = request.args.get('limit', type=int)
hosptials_data_len = len(hosptials_data)
if skip < 0 or limit < 0 or limit > 50:
raise Exception('Bad input parameter.')
if skip > hosptials_data_len:
raise Exception("Index out of range.")
if skip + limit > hosptials_data_len:
limit = hosptials_data_len - skip
resp['data'] = hosptials_data[skip:skip+limit]
else:
resp['data'] = hosptials_data
resp['success'] = True
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False),(400 if not resp['success'] else 200)
@data.route('/hotel_list')
@auth.login_required
def hotel_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(current_app.config['HOTEL_PATH'], HOTEL_HEADERS)
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/logistical_list')
@auth.login_required
def logistical_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_with_medical_supplier(current_app.config['LOGISITICAL_PATH'], LOGISTICS_HEADERS)
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/news_list')
@auth.login_required
def news_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(current_app.config['NEWS_PATH'], NEWS_HEADERS)
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/donation_list')
@auth.login_required
def donation_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(current_app.config['DONATION_PATH'], DONATION_HEADERS)
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/factory_list')
@auth.login_required
def factory_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_with_medical_supplier(current_app.config['FACTORY_PATH'], FACTORY_HEADERS)
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/clinic_list')
@auth.login_required
def clinic_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(current_app.config['CLINIC_PATH'], CLINIC_HEADERS)
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/hospital_list_json')
def hospital_list_json():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data= json_helper(current_app.config['JSON_HOSPITAL_PATH'])
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/hotel_list_json')
def hotel_list_json():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = json_helper(current_app.config['JSON_HOTEL_PATH'])
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/logstics_list_json')
def logstics_list_json():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = json_helper(current_app.config['JSON_LOGISITICAL_PATH'])
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/news_list_json')
def news_list_json():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = json_helper(current_app.config['JSON_NEWS_PATH'])
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/donation_list_json')
def donation_list_json():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = json_helper(current_app.config['JSON_DONATION_PATH'])
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/factory_list_json')
def factory_list_json():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = json_helper(current_app.config['JSON_FACTORY_PATH'])
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)
@data.route('/clinic_list_json')
def clinic_list_json():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = json_helper(current_app.config['JSON_CLINIC_PATH'])
resp['success'] = True
resp['data'] = resp_data
except Exception as e:
resp['msg'] = str(e)
return json.dumps(resp, ensure_ascii=False)