#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sqlite3
from faker import Faker
conn = sqlite3.connect('test.db')
print "Opened database successfully";
cur = conn.cursor()
cur.execute("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'person'")
if not cur.fetchone():
conn.execute('''CREATE TABLE person
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
country TEXT,
state TEXT,
city TEXT,
address TEXT,
postcode TEXT,
latitude REAL,
longitude REAL,
phoneNumber TEXT,
birthday DATE,
email TEXT
);''')
print "Table created successfully"
fake = Faker()
i = 0
while i < 10000:
sql = 'INSERT INTO person (name, country, state, city, address, postcode, latitude, longitude, phoneNumber, birthday, email) VALUES (?,?,?,?,?,?,?,?,?,?,?);'
data = []
j = 0
while j < 500:
# sql = sql + '(?,?,?,?,?,?,?,?,?,?,?),'
data.append((
fake.name(), fake.country(), fake.state(), fake.city(), fake.address(), fake.postcode(),
float(fake.latitude()),
float(fake.longitude()), fake.phone_number(), fake.date(), fake.email()))
j = j + 1
sql = sql[:-1] + ';'
cur.executemany(sql, data)
i = i + 1
conn.commit()
cur.execute('SELECT * FROM person')
print cur.fetchall()
conn.close()