-
Notifications
You must be signed in to change notification settings - Fork 1
/
insert-init.py
31 lines (28 loc) · 975 Bytes
/
insert-init.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
from api import mongo, utils
from api.schema import Disease, Remedy, ComplexHandler
import csv, json
def insertDisease(name):
if not mongo.db.diseases.find_one({'name' : name}):
d = Disease()
d.name = name
d.description = 'description for ' + name
d.remedyName = 'Remedy for ' + name
d = utils.getJson(d)
mongo.db.diseases.insert(d)
def insertRemedy(disease, remedyDescription):
remedyName = 'Remedy for ' + disease
if not mongo.db.remedies.find_one({'name' : remedyName}):
r = Remedy()
r.name = remedyName
r.description = remedyDescription
r.medicine = ''
r.dose = ''
r.remarks = ''
r = utils.getJson(r)
mongo.db.remedies.insert(r)
with open('crowdai_labels.csv') as csvfile:
reader = csv.reader(csvfile)
for line in reader:
insertDisease(line[0])
insertRemedy(line[0], line[1])
print('inserted: ', line[0])