Created
October 18, 2019 02:38
-
-
Save zhaobenx/8262928b26458d09eadc31f4eb307d5b to your computer and use it in GitHub Desktop.
给傻逼的Database作业填一些fake的data。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on 2019-10-17 20:09:09 | |
@Author: ZHAO Lingfeng | |
@Version : 0.0.1 | |
""" | |
import random | |
from faker import Faker | |
# pylint: disable=maybe-no-member | |
fake = Faker() | |
def id(count, digit=4): | |
i = 1 | |
i += 10 ** (digit - 1) | |
for _ in range(count): | |
yield i | |
i += 1 | |
COUNTER = 10000 | |
def incresting_id(): | |
global COUNTER | |
COUNTER += 1 | |
return COUNTER | |
def name(): | |
return fake.name() | |
def f_name(): | |
return fake.first_name() | |
def l_name(): | |
return fake.last_name() | |
def address(limit=20): | |
return fake.street_address()[:limit] | |
def city(): | |
return fake.city() | |
def state(): | |
return fake.state() | |
def zipcode(): | |
return fake.zipcode() | |
def phone(): | |
# return fake.phone_number() | |
return random.randint(1000000000, 9999999999) | |
def date(): | |
return fake.date() | |
def date_future(): | |
return fake.date_between("today", "+30y") | |
def description(): | |
des = ["A good one", "Amazing one", "Unbalblible one", "keyide one", "Explosion"] | |
return random.choice(des) | |
def finish(): | |
fi = ["Dye", "Oil finishes", "Shellac", "Lacquers"] | |
return random.choice(fi) | |
def price(): | |
return random.randint(1000, 200000) / 100 | |
def project_name(): | |
p1 = ["Create", "Design", "Clean", "Make", "Try"] | |
p2 = ["human", "cat", "food", "fire", "god", "tree", "rain"] | |
return random.choice(p1) + " " + random.choice(p2) | |
def equipment_name(): | |
pre = ["Consumer grade", "Restricted", "Exceedingly Rare", "Contraband"] | |
eq = ["Balance", "Ring Stand", "Scoopula", "Beaker"] | |
return random.choice(pre) + " " + random.choice(eq) | |
def a(): | |
chemist = ( | |
lambda id_4: f"insert into CHEMIST values ({id_4}, '{f_name().upper()}', '{l_name().upper()}', '{address(50)}', '{city()}',' {state()}', '{zipcode()}', '{phone()}');" | |
) | |
project = ( | |
lambda id_5: f"insert into PROJECT values ({id_5}, '{project_name()}', (date '{date()}'), (date '{date_future()}'));" | |
) | |
equipment = ( | |
lambda id_6: f"insert into EQUIPMENT values ({id_6}, '{equipment_name()}', {random.randint(1,20)});" | |
) | |
chemist_project = ( | |
lambda id_5, id_4: f"insert into CHEMIST_PROJECT values (date '{date_future()}', {id_4}, {id_5});" | |
) | |
chemist_equipment = ( | |
lambda id_4, id_6: f"insert into CHEMIST_EQUIPMENT values (date '{date()}', {id_4}, {id_6});" | |
) | |
for i in id(10, 4): | |
print(chemist(i)) | |
for i in id(10, 5): | |
print(project(i)) | |
for i in id(10, 6): | |
print(equipment(i)) | |
for i, j in zip(id(10, 5), id(10, 4)): | |
print(chemist_project(i, j)) | |
for i, j in zip(id(10, 4), id(10, 6)): | |
print(chemist_equipment(i, j)) | |
def b(): | |
customer = ( | |
lambda id: f"insert into CUSTOMER values({id}, '{name()}', '{address(20)}', '{city()}', '{state()}', {zipcode()});" | |
) | |
orders = ( | |
lambda id_o, id_c: f"insert into ORDERS values({id_o}, DATE '{date()}', {id_c});" | |
) | |
product = ( | |
lambda id: f"insert into PRODUCT values({id}, '{description()}', '{finish()}','{price()}');" | |
) | |
invoice = ( | |
lambda id_o, id_p: f"insert into INVOICE values({random.randint(1,200)}, {id_o}, {id_p}, {incresting_id()});" | |
) | |
for i in id(10, 4): | |
print(customer(i)) | |
for i, j in zip(id(10, 5), id(10, 4)): | |
print(orders(i, j)) | |
for i in id(10, 5): | |
print(product(i)) | |
for i, j in zip(id(10, 5), id(10, 5)): | |
print(invoice(i, j)) | |
def main(): | |
a() | |
b() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment