-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake.py
36 lines (29 loc) · 1.1 KB
/
fake.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
import random
from faker import Faker
from werkzeug.security import generate_password_hash
from app import app
from exts import db
from models import UserModel, PostModel, CommentModel
fa = Faker(locale='zh-CN')
def generate_user():
for i in range(10):
hash_password = generate_password_hash("123455")
user = UserModel(username=fa.user_name().strip().lower(), email=fa.email(), password=hash_password)
db.session.add(user)
db.session.commit()
def generate_post():
for i in range(20):
content = ''
for text in fa.texts():
content += text
p = PostModel(post_name=fa.sentence(), description=content, author_id=random.randint(1, 10), category=random.choice(["游戏区","唠嗑区","程序区"]))
db.session.add(p)
db.session.flush()
db.session.commit()
def generate_comment():
for i in range(50):
comment = CommentModel(content=fa.sentence()+"\n", post_id=random.randint(15, 30), author_id=random.randint(1, 10))
db.session.add(comment)
db.session.commit()
with app.app_context():
generate_comment()