-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdatedb.py
More file actions
30 lines (21 loc) · 975 Bytes
/
Copy pathupdatedb.py
File metadata and controls
30 lines (21 loc) · 975 Bytes
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
import mysql.connector
from datetime import datetime
import random
def update_schema(schema, data):
db = mysql.connector.connect(
host="localhost",
user="root",
password="22dollars",
database=schema
)
twt_to_add = ''
for idx, row in data.iterrows():
new_timestamp = datetime.strftime(row[3],'%Y-%m-%d %H:%M:%S') # datetime.strptime(row[3],'%a %b %d %H:%M:%S +0000 %Y'),
twt_to_add = twt_to_add + "({}, '{}', '{}', '{}', {}, '{}'),".format(row[6], row[2].replace("'", ""),
new_timestamp, row[0],
random.randint(1, 148), row[5])
cursor = db.cursor()
query1 = "insert into tweet (hashtag_id, text, datetime, username, location_id," \
" twitter_ident) values {};".format(twt_to_add[:-1])
cursor.execute(query1)
db.commit()