-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathseed.py
110 lines (78 loc) · 3.52 KB
/
seed.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
"""Utility file to seed image database from FDA data in seed_data/"""
from sqlalchemy import func
from model import Meds, Users, User_meds
from model import connect_to_db, db
from server import app
from datetime import datetime
import csv
def load_pill_data():
"""Seed database with pillbox data. """
Meds.query.delete()
# '/home/vagrant/src/hb_pillproject/pill_testing_book.csv'
with open('Pillbox_production.csv') as csvfile:
csv_reader = csv.reader(csvfile)
line_count = 0
# print(csv_reader)
for row in csv_reader:
# print(row)
if line_count == 0:
print(f'This is the first row.')
print('#############')
line_count += 1
else:
print('THIS IS NOT THE FIRST ROW')
print('#############')
shape = (row[9]).upper()
print(f'{shape} = shape',type(shape))
score = (row[11]).upper()
print(f'{score} = score', type(score))
imprint = (row[13]).upper()
print(f'{imprint} = imprint', type(imprint))
color = (row[16]).upper()
print(f'{color} = color', type(color))
strength = (row[18]).upper()
print(f'{strength} = strength', type(strength))
print(len(strength))
rxcui = row[24]
print(f'{rxcui} = rxcui', type(rxcui))
ndc9 = row[29]
print(f'{ndc9} = ndc9', type(ndc9))
medicine_name = (row[32]).capitalize()
print(f'{medicine_name} = medicine_name',type(medicine_name))
print(len(medicine_name))
image_label = row[45]
print(f'{image_label} = image_label', type(image_label))
has_image = row[46]
if has_image == 'TRUE':
has_image = True
img_path = ("https://res.cloudinary.com/ddvw70vpg/image/upload/v1573537498/production_images/"
+ image_label + ".jpg")
else:
has_image = False
img_path = ("https://res.cloudinary.com/ddvw70vpg/image/upload/v1574898450/production_images/No_Image_Available.jpg")
print(f'{has_image} = does this have an image',type(has_image))
print(f'{img_path} ##IMAGE PAGE IS THIS##', type(img_path))
#shape= row['splshape']
medication = Meds(shape=shape,
score=score,
imprint=imprint,
color=color,
strength=strength,
rxcui=rxcui,
ndc9=ndc9,
medicine_name=medicine_name,
image_label=image_label,
has_image=has_image,
img_path=img_path)
print(medication)
db.session.add(medication)
# print(f'\t{row[32]} has been created with an rxcui of {row[24]}.')
line_count += 1
# print(f'Processed {line_count} lines.')
db.session.commit()
if __name__ == "__main__":
connect_to_db(app)
# In case tables haven't been created, create them
db.create_all()
# Import different types of data
load_pill_data()