forked from wuhan2020/api-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
167 lines (144 loc) · 3.94 KB
/
Copy pathutils.py
File metadata and controls
167 lines (144 loc) · 3.94 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
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
# -*- coding: utf-8 -*-
from flask import Blueprint
import os
import json
import datetime
import platform
import csv
import os
import traceback
import yaml
from const import *
data = Blueprint('register', __name__)
if platform.system()=="Linux":
path_home="/home/wuhan2020/wuhan2020"
else:
from index import app
path_home=os.path.join(app.root_path,"wuhan2020")
# wuhan2020文件夹为https://github.com/wuhan2020/wuhan2020项目文件的本地clone
# 阿里云serverless使用挂载nas远程目录来存放缓存文件;在本机调试时,缓存文件夹将存放在项目根目录
if not os.path.exists(path_home):
os.mkdir(path_home)
"""
CACHE PATH
"""
HOSPITAL_PATH = os.path.join(path_home, "HOSPITAL.csv")
HOTEL_PATH = os.path.join(path_home, "HOTEL.csv")
LOGISITICAL_PATH = os.path.join(path_home, "LOGISTICAL.csv")
NEWS_PATH = os.path.join(path_home, "NEWS.csv")
DONATION_PATH = os.path.join(path_home, "DONATION.csv")
FACTORY_PATH = os.path.join(path_home, "FACTORY.csv")
CLINIC_PATH = os.path.join(path_home, "CLINIC.csv")
"""
Tools
"""
def csv_helper(fpath, headers):
result = []
with open(fpath) as f:
for line in f.readlines()[1:]:
csv_data = line.strip().split(",")
result.append(dict(zip(headers,csv_data)))
return result
def yaml_helper(fpath):
result = []
with open(fpath, 'r') as f:
result = yaml.load(f)
return result
@data.route('/hospital_list')
def hospital_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(HOSPITAL_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('/hotel_list')
def hotel_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(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('/logstics_list')
def logstics_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(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')
def news_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(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')
def donation_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(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')
def factory_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(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')
def clinic_list():
resp = {
'success': False,
'data': [],
'msg': '',
}
try:
resp_data = csv_helper(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)