コード例 #1
0
ファイル: demo.py プロジェクト: lterelak/VirtualAssistants
    def run(self):
        faker = Faker(
            cls=VirtualAssistant,
            init={
                "id":
                generator.Sequence(),
                "name":
                generator.Name(),
                "last_name":
                generator.Name(),
                "job":
                generator.String(
                    "(1st pressman|1st Pressman On Web Press|2nd Grade Teacher|2nd pressman|3d animator)"
                ),
                "image_filename":
                generator.String("[0-9]{1,2}.jpg"),
                "image_url":
                generator.String(
                    "(https://fwcdn.pl/ppo/70/74/57074/449882.2.jpg|https://fwcdn.pl/ppo/01/09/109/449960.2.jpg|https://fwcdn.pl/ppo/03/16/316/449937.2.jpg|https://ssl-gfx.filmweb.pl/ph/06/99/640699/831926_1.2.jpg|https://ssl-gfx.filmweb.pl/ph/97/46/399746/245837_1.2.jpg)"
                ),
            })

        #Create 5 virtul assistants
        for assistant in faker.create(5):
            print("Adding VirtualAssistant: %s" % assistant)
            self.db.session.add(assistant)
コード例 #2
0
    def run(self):
        today = date.today()
        faker = Faker(cls=Assistant,
                      init={
                          "id": generator.Sequence(),
                          "firstname": generator.Name(),
                          "lastname": generator.Name(),
                          "email": generator.String(),
                          "occupation": generator.String(),
                          "creationdate": today,
                          "filename": "default.png"
                      })

        for assistant in faker.create(5):
            print("Adding assistant: %s" % Assistant)
            self.db.session.add(assistant)
コード例 #3
0
    def run(self):
        # Create a new Faker and tell it how to create User objects
        faker = Faker(cls=models.User,
                      init={
                          "id": None,
                          "name": generator.String('[a-z]\d{4}\c{3}'),
                          "created_at": None,
                          "created_by": 'system',
                          "updated_at": None,
                          "updated_by": '',
                          "email": generator.String('[a-z]\d{4}\c{3}@test.com')
                      })

        # Create 3 users
        for user in faker.create(3):
            print("Adding user: %s" % user)
            # Flask-Seeder will by default commit all changes to the database.
            self.db.session.add(user)
コード例 #4
0
    def run(self):
        books = Faker(cls=Book,
                      init={"title": generator.String("Book [A-Z][a-z]{4}")})

        authors = Faker(cls=Author, init={"name": generator.Name()})

        for book in books.create(20):
            print(f"Adding book: {book.title}")
            self.db.session.add(book)

        for author in authors.create(8):
            print(f"Adding author: {author.name}")
            self.db.session.add(author)
コード例 #5
0
    def run(self):
        faker = Faker(
            cls=Question,
            init={
                "question":
                generator.String(
                    'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent vitae nulla pretium, euismod neque ut, feugiat est. Curabitur eleifend lacus vel malesuada ornare. Suspendisse volutpat turpis elit, a facilisis orci facilisis sed. Praesent sed nulla non massa tempor tincidunt. Curabitur lobortis ac elit non ullamcorper. Fusce auctor egestas libero. Aliquam vel rutrum tellus. Phasellus ut quam condimentum, tempus tellus vel, faucibus nulla. Duis eu ligula sodales, viverra dolor at, tincidunt elit. Nunc ut pharetra tellus, sit amet euismod quam. Suspendisse aliquet ligula fermentum, suscipit lacus vitae, imperdiet est. In consectetur lacus at dignissim facilisis.'
                ),
                "like_count":
                generator.Integer(start=0, end=100)
            })

        for question in faker.create(20):
            print("Adding question: %s" % question)
            self.db.session.add(question)
コード例 #6
0
    def run(self):
        date = datetime.now()

        faker = Faker(cls=Trucker,
                      init={
                          'name': generator.Name(),
                          'age': generator.Integer(start=18, end=60),
                          'whatsapp': generator.String(r'+55\d{11}'),
                          'last_latitude': '-10',
                          'last_longitude': '-10',
                          'created_date': date
                      })

        for trucker in faker.create(5):
            print('Adding trucker: %s' % trucker)
            self.db.session.add(trucker)
コード例 #7
0
    def run(self):
        # Create a new Faker and tell it how to create User objects
        faker = Faker(cls=User,
                      init={
                          "first_name":
                          generator.Name(),
                          "last_name":
                          generator.Name(),
                          "email":
                          generator.String("[a-z]{6,11}[0-9]{2,5}@gmail.com"),
                          "age":
                          generator.Integer(start=20, end=100),
                          "is_employee":
                          bool(random.uniform(0, 1)),
                      })

        for user in faker.create(1_000_000):
            print(f"Adding user: {user}")
            self.db.session.add(user)
コード例 #8
0
    def run(self):
        obj = db.session.query(Job).order_by(Job.id.desc()).first()

        faker = Faker(
            cls=Assistant,
            init={
                "name": generator.Name(),
                "surname": generator.Name(),
                "picture_file": generator.String('(seeder_prof/)\d(.jpg)'),
                "job": generator.Integer(start=1, end=obj.id)
            }
        )

        # Create 15 assistants
        for assistant in faker.create(15):
            job = Job.query.filter_by(id=assistant.job).first()
            assistant.job = job.text
            print("Adding user: %s" % assistant)
            self.db.session.add(assistant)
コード例 #9
0
    def run(self):
        # Create a new Faker and tell it how to create User objects

        print("EMPTING DATABASE")
        self.db.drop_all()
        self.db.create_all()

        print("ADDING BASE USERS")
        user_seeds = [
            {
                'username': '******',
                'password': '******',
                'role': 'admin'
            },
            {
                'username': '******',
                'password': '******',
                'role': 'planner'
            },
            {
                'username': '******',
                'password': '******',
                'role': 'maintainer'
            },
        ]

        for seed in user_seeds:
            user = UserModel(**seed)
            print("Adding user ", user.json())
            self.db.session.add(user)

        print("ADDING MAINTAINER USERS")
        faker = Faker(cls=UserModel,
                      init={
                          "username": generator.Name(),
                          "password": "******",
                          "role": "maintainer"
                      })

        # Create 5 more maintainers
        for user in faker.create(5):
            print("Adding user ", user.json())
            self.db.session.add(user)

        print("ADDING MAINTENANCE ACTIVITIES")
        faker = Faker(cls=MaintenanceActivityModel,
                      init={
                          'activity_type':
                          'planned',
                          'site':
                          generator.String("\c{10,30}"),
                          'typology':
                          generator.String("\c{10,30}"),
                          'description':
                          generator.String("\c{40,100}"),
                          'estimated_time':
                          generator.Integer(10, 100),
                          'interruptible':
                          random.choice([True, False]),
                          'materials':
                          random.choice([generator.String("\c{10,30}"), None]),
                          'week':
                          generator.Integer(1, 52),
                          'workspace_notes':
                          random.choice([generator.String("\c{40,100}"), None])
                      })

        # Creates 150 maintenance activities
        for activity in faker.create(150):
            print("Adding activity ", activity.json())
            self.db.session.add(activity)

        print("SEEDING COMPLETED")