示例#1
0
def seed():
    # generate fake sms
    fake_sms_number = 10

    print("seeding sms...")
    for i in range(fake_sms_number):
        africastalking_sms_id = generator.Integer(start=10000, end=99999).generate()
        phone_number = generator.Integer(start=10000000, end=99999999).generate()
        country_code = '+2547'
        message = lorem.paragraph()
        africastalking_sms_cost = generator.Integer(start=20, end=100).generate()

        sms_kwargs = {
            "africastalking_sms_id": africastalking_sms_id,
            "phone": f'{country_code}{phone_number}',
            "message": message,
            "africastalking_sms_cost": f'KES {africastalking_sms_cost}',
            "send_at": datetime.datetime.now(),
            "farmer_id": str(uuid.uuid4()),
            "provider_id": str(uuid.uuid4())
        }

        sms = SMSMessage(**sms_kwargs)
        db.session.add(sms)
        db.session.commit()
    print("done sms")
示例#2
0
    def run(self):
        faker = Faker(
            cls=Answer,
            init={
                "answer":
                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.'
                ),
                "question_id":
                generator.Integer(start=1, end=20),
                "like_count":
                generator.Integer(start=0, end=100)
            })

        for answer in faker.create(150):
            print("Adding answer: %s" % answer)
            self.db.session.add(answer)
示例#3
0
    def run(self):
        _id = generator.Sequence()

        faker_for_state = Faker(cls=StateCasesPerDay,
                                init={
                                    'id':
                                    _id,
                                    'date':
                                    DateGenerator('-15d', 'now'),
                                    'country':
                                    'Brazil',
                                    'state_id':
                                    StateGeneratorRandom(),
                                    'newcases':
                                    generator.Integer(start=0, end=12),
                                    'totalcases':
                                    generator.Integer(start=10, end=20)
                                })

        faker_for_total = Faker(cls=StateCasesPerDay,
                                init={
                                    'id':
                                    _id,
                                    'date':
                                    DateGenerator('-15d', 'now'),
                                    'country':
                                    'Brazil',
                                    'state_id':
                                    'TOTAL',
                                    'newcases':
                                    generator.Integer(start=0, end=12),
                                    'totalcases':
                                    generator.Integer(start=10, end=20)
                                })

        for state in faker_for_state.create(10):
            print("Adding state per day: %s" % state)
            self.db.session.add(state)

        for state in faker_for_total.create(10):
            print("Adding state per day: %s" % state)
            self.db.session.add(state)
示例#4
0
    def run(self):
        _id = generator.Sequence()
        __id = generator.Sequence()

        faker_for_state = Faker(
            cls=StateCases,
            init={
                'id': _id,
                'country': 'Brazil',
                'state_id': __id,
                'totalcases': generator.Integer(start=10, end=20),
                'totalcasesms': generator.Integer(start=1, end=10),
                'notconfirmedbyms': generator.Integer(start=1, end=10),
                'deaths': generator.Integer(start=0, end=2),
                'url': 'https://someurl.com.br'

            }
        )

        faker_for_total = Faker(
            cls=StateCases,
            init={
                'id': _id,
                'country': 'Brazil',
                'state_id': __id,
                'totalcases': 100,
                'totalcasesms': 50,
                'notconfirmedbyms': 50,
                'deaths': 10,
                'url': 'https://someurl.com.br'

            }
        )

        for state in faker_for_total.create(1):
            print("Adding state case: %s" % state)
            self.db.session.add(state)

        for state in faker_for_state.create(27):
            print("Adding state case: %s" % state)
            self.db.session.add(state)
示例#5
0
    def run(self):
        # Create a new Faker and tell it how to create User objects
        faker = Faker(cls=User,
                      init={
                          "id_num": generator.Sequence(),
                          "name": generator.Name(),
                          "age": generator.Integer(start=20, end=100)
                      })

        # Create 5 users
        for user in faker.create(5):
            print("Adding user: %s" % user)
            self.db.session.add(user)
示例#6
0
    def run(self):

        faker_for_city = Faker(cls=City,
                               init={
                                   'id':
                                   generator.Sequence(start=1, end=1000),
                                   'ibge_id':
                                   generator.Integer(start=300000, end=399999),
                                   'country':
                                   'Brazil',
                                   'city':
                                   'Test',
                                   'deaths':
                                   1,
                                   'state_id':
                                   generator.Integer(start=2, end=28),
                                   'totalcases':
                                   generator.Integer(start=1, end=10)
                               })

        for case in faker_for_city.create(500):
            print("Adding city case: %s" % case)
            self.db.session.add(case)
    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)
示例#8
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)
示例#9
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)
示例#10
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")