-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfake_data_make_dbsave.py
More file actions
31 lines (26 loc) · 909 Bytes
/
fake_data_make_dbsave.py
File metadata and controls
31 lines (26 loc) · 909 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
31
"""
CREATE TABLE `test`.`user` (
`no` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`sex` VARCHAR(1) NULL,
`ssn` VARCHAR(14) NULL,
`email` VARCHAR(45) NULL,
PRIMARY KEY (`no`));
"""
from faker import Faker
import pymysql
conn = pymysql.connect(host="localhost", user="root", password="1234", db="test", charset="utf8")
curs = conn.cursor()
fake = Faker("ko_KR")
with open("fake_data.csv", "w", encoding="utf-8", newline='') as f:
for _ in range(1000):
profile = fake.profile()
print(profile['name'], profile['sex'], profile['ssn'], profile['mail'])
try:
sql = "insert into user (name, sex, ssn, email)" \
"values (%s, %s, %s, %s)"
curs.execute(sql, (profile['name'], profile['sex'], profile['ssn'], profile['mail']))
except:
pass
conn.commit()
conn.close()