-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_make.py
177 lines (136 loc) · 4.32 KB
/
insert_make.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
import pandas as pd
def tweets_table_insert():
# first I am going to work on making the inserts from the CSV for Tweets Table
'''
id SERIAL PRIMARY KEY NOT NULL,
text VARCHAR(280) NOT NULL,
location VARCHAR,
favorite BOOLEAN NOT NULL,
date TIMESTAMP NOT NULL,
rt BOOLEAN NOT NULL,
'''
#syntax for insert
'''
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
'''
data = pd.read_csv('./cleaned_data/tweets.csv')
length = data.shape
rows = length[0]
id = [i for i in range(rows)]
text = data[['text']]
location = data[['location']]
favorite = data[['favorite']]
date = data[['date']]
rt = data[['rt']]
list_of_queries = []
current = ''
for x in range(rows):
zero = int(id[x])
one = str(text.at[x,'text'])
two = str(location.at[x,'location'])
three = str(favorite.at[x,'favorite'])
four = str(date.at[x,'date'])
five = str(rt.at[x,'rt'])
list_of_queries.append("INSERT INTO Tweets (id, text, location, favorite, date, rt) VALUES ({0},'{1}','{2}','{3}','{4}', '{5}');".format(zero, one, two, three, four, five))
f = open('insert/tweets_table_insert.sql', 'w')
for x in list_of_queries:
f.write(x+'\n')
f.close()
def users_insert():
'''
create table Users
(
id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR NOT NULL,
screen_name VARCHAR UNIQUE NOT NULL,
geo_enabled BOOLEAN NOT NULL,
verified BOOLEAN NOT NULL
)
'''
#syntax for insert
'''
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
'''
data = pd.read_csv('cleaned_data/user.csv')
length = data.shape
rows = length[0]
id = [i for i in range(rows)]
name = data[['name']]
screen_name = data[['screen_name']]
geo_enabled = data[['geo_enabled']]
verified = data[['verified']]
list_of_queries = []
for x in range(rows):
zero = int(id[x])
one = str(name.at[x,'name'])
two = str(screen_name.at[x, 'screen_name'])
three = str(geo_enabled.at[x, 'geo_enabled'])
four = str(verified.at[x, 'verified'])
list_of_queries.append("INSERT INTO Type (id, name, screen_name, geo_enabled, verified) VALUES ({0}, '{1}', '{2}', '{3}', '{4}');".format(zero, str(one), two, three, four))
f = open('insert/users_insert.sql', 'w')
for x in list_of_queries:
f.write(x+'\n')
f.close()
def flu_insert():
'''
create table Flu
(
flu_id SERIAL PRIMARY KEY NOT NULL,
type VARCHAR NOT NULL
)
'''
#syntax for insert
'''
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
'''
data = pd.read_csv('cleaned_data/flu.csv')
length = data.shape
rows = length[0]
flu_id = [i for i in range(rows)]
type_ = data[['type']]
list_of_queries = []
for x in range(rows):
zero = int(flu_id[x])
one = str(type_.at[x,'type'])
list_of_queries.append("INSERT INTO Flu (flu_id, type) VALUES ({0},'{1}');".format(zero, str(one)))
f = open('insert/flu_insert.sql', 'w')
for x in list_of_queries:
f.write(x+'\n')
f.close()
def symptoms_insert():
'''
create table Symptoms
(
symptoms_id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR NOT NULL,
description VARCHAR UNIQUE NOT NULL
)
'''
#syntax for insert
'''
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
'''
data = pd.read_csv('cleaned_data/symptoms.csv')
length = data.shape
rows = length[0]
symptoms_id = [i for i in range(rows)]
name = data[['name']]
description = data[['description']]
list_of_queries = []
for x in range(rows):
zero = int(symptoms_id[x])
one = str(name.at[x,'name'])
two = str(description.at[x, 'description'])
list_of_queries.append("INSERT INTO Symptoms (symptoms_id, name, description) VALUES ({0},'{1}','{2}');".format(zero, one, two))
f = open('insert/symptoms_insert.sql', 'w')
for x in list_of_queries:
f.write(x+'\n')
f.close()
# tweets_table_insert()
# users_insert()
# flu_insert()
symptoms_insert()