Ejemplo n.º 1
0
    def fake_users(cls, num):
        users = []
        # 下面就要开始创建用户信息了,创建多少个我们用for循环来控制
        for i in range(num):
            year = random.randint(1980, 2002)
            month = random.randint(1, 12)
            day = random.randint(1, 28)

            username = random_zh_str(3)
            password = '******'
            gender = random.choice(['男', '女', '保密'])
            birthday = '%04d-%02d-%02d' % (year, month, day)
            city = random.choice(['上海', '北京', '广州', '深圳', '池州', '安庆', '马鞍山'])
            address = random_zh_str(6)
            #phone = random.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 6)
            phone = make_num()

            user = cls(username=username,
                       password=password,
                       gender=gender,
                       birthday=birthday,
                       city=city,
                       address=address,
                       phone=phone)
            users.append(user)

        # 执行添加数据
        db.session.add_all(users)
        db.session.commit()
        return users
Ejemplo n.º 2
0
    def fake_users(cls, num):
        users = []
        for i in range(num):
            year = random.randint(1980, 2000)
            month = random.randint(1, 12)
            day = random.randint(1, 28)

            nickname = random_zh_str(3)
            password = '******'
            gender = random.choice(['male', 'female', 'unknow'])
            birthday = '%04d-%02d-%02d' % (year, month, day)
            city = random.choice(['上海', '北京', '南京', '北海', '乌鲁木齐', '威海', '许昌', '郑州'])
            bio = random_zh_str(30)
            created = '2013-11-12'
            user = cls(nickname=nickname, password=password, gender=gender,
                       birthday=birthday, city=city, bio=bio, created=created)
            users.append(user)
        db.session.add_all(users)
        db.session.commit()
        return users
Ejemplo n.º 3
0
    def fake_users(cls, num):
        users = []
        for i in range(num):
            year = random.randint(2010, 2019)
            month = random.randint(1, 12)
            day = random.randint(1, 28)

            username = random_zh_str(3)
            password = '******'
            gender = random.choice(['male', 'female', 'unknow'])
            birthday = '%04d-%02d-%02d' % (year, month, day)
            city = random.choice(['上海', '苏州', '长沙', '哈尔滨', '长春', '北京'])
            bio = random_zh_str(30)
            created = '2010-02-28'
            user = cls(username=username,
                       password=password,
                       gender=gender,
                       birthday=birthday,
                       city=city,
                       bio=bio,
                       created=created)
Ejemplo n.º 4
0
    def fake_weibos(cls, uid_list, num):
        wb_list = []
        for i in range(num):
            year = random.randint(2010, 2019)
            month = random.randint(1, 12)
            day = random.randint(1, 28)
            date = '%04d-%02d-%02d' % (year, month, day)

            uid = random.choice(uid_list)
            content = random_zh_str(random.randint(70, 140))
            wb = cls(uid=uid, content=content, created=date, updated=date)
            wb_list.append(wb)

        db.session.add_all(wb_list)
        db.session.commit()
Ejemplo n.º 5
0
    def fake_users(cls, num):
        users = []
        for i in range(num):
            username = random_zh_str(3)
            password = '******'
            gender = random.choice(['男', '女'])
            phone = '123456789'
            create_time = '2000-01-21'
            user = cls(username=username,
                       password=password,
                       gender=gender,
                       phone=phone,
                       create_time=create_time)
            users.append(user)

        db.session.add_all(users)
        db.session.commit()
        return users