Пример #1
0
    def handle(self, n, *args, **options):
        # Expense.objects.all().delete()

        users = []
        for i in range(1, 6):
            username = f"user{i}"
            # get_or_create
            try:
                u = User.objects.create_user(username, password=username)
                for c in random.sample(CATS, random.randint(2, 5)):
                    u.categories.create(name=c)
                users.append(u)
            except IntegrityError:
                users.append(User.objects.get(username=username))

        for i in range(n):
            u = random.choice(users)
            Expense.objects.create(
                user=u,
                category=u.categories.order_by("?").first(),
                title=silly.thing(),
                amount=random.randint(1, 10000) / 100,
                date=f"2020-05-{random.randint(1, 20):02}",
                description="\n".join(
                    [silly.sentence() for i in range(random.randint(1, 4))]),
            )
Пример #2
0
 def handle(self, *args, **options):
     for i in range(10):
         p = models.Post(
             title=silly.sentence(),
             content=silly.markdown(length=5),
         )
         p.save()
Пример #3
0
 def handle(self, *args, **options):
     o = models.Expense.objects.create(
         account=models.Account.objects.order_by("?").first(),
         amount=silly.number() * 100,
         date=silly.datetime().date(),
         title=silly.sentence(),
     )
     print(o.id)
     print(o.title)
Пример #4
0
 def handle(self, *args, **options):
     while User.objects.count() < 10:
         User.objects.create_user(
             username=silly.firstname().lower(),
             password="******",
         )
     users = list(User.objects.all())
     n = 10
     for i in range(n):
         o = Expense(
             user=random.choice(users),
             created_at=silly.datetime(),
             title="{} {}".format(silly.adjective(), silly.noun()),
             amount=str(silly.number() + silly.number() / 10)[:5],
             description=silly.sentence() + "\n" + silly.sentence()
         )
         o.full_clean()
         o.save()
         o.created_at = silly.datetime()
         o.save()
Пример #5
0
    def handle(self, *args, **options):
        fake = Faker("he_IL")
        images = glob.glob(f"{IMG_PATH}/image*.jpeg")

        try:
            User.objects.create_superuser('sysop', '', 'sysop')
        except IntegrityError:
            pass

        with SAMPLE_PROJECTS_FILE.open(encoding="utf-8") as f:
            for i, proj in enumerate(load_projects(json.load(f))):
                with transaction.atomic():
                    print(proj['slug'])
                    project = Project()
                    project.name = proj['name']
                    project.slug = proj['slug']
                    project.geom = proj['polygon']
                    project.center = proj['polygon'].centroid
                    f = (IMG_PATH / f"logo_{i + 1:04d}.jpeg").open("rb")
                    project.logo_file.save(f"logo{i + 1}.jpeg", File(f))
                    project.save()

                    for _ in range(
                            self.LOCATIONS_PER_PROJECT):
                        location = Location()
                        location.project = project
                        location.name = fake.street_name() + " " + fake.street_name()
                        x0, y0, x1, y1 = project.geom.extent
                        x = random.uniform(x0, x1)
                        y = random.uniform(y0, y1)
                        location.point = Point(x, y)
                        location.information = silly.sentence()
                        location.save()

                        for _ in range(
                                random.randint(0,
                                               self.PHOTOS_PER_LOCATION)):
                            photo = Photo()
                            photo.name = fake.street_name()
                            photo.location = location
                            photo.date_taken = silly.datetime().date()
                            photo.lond_desc = fake.paragraphs(nb=3,
                                                              ext_word_list=None)
                            with open(random.choice(images), "rb") as f:
                                photo.photo_file.save("random.jpg", File(f))
                            photo.save()
Пример #6
0
def create_tasks(qty: int):

    for _ in range(0, qty):
        time.sleep(0.01)
        todo_information = {
            "todo_id": str(uuid.uuid1()),
            "title": silly.thing(),
            "description": silly.sentence(),
            "date_due": currentTime + timedelta(days=random.randint(1, 180)),
            "is_complete": bool(random.getrandbits(1)),
            "date_create": currentTime,
            "date_update": currentTime,
            "user_id": str(uuid.uuid4()),
            "date_complete": None,
        }

        db_todo_call(todo_information)
Пример #7
0
    def handle(self, *args, **options):
        images = glob.glob(f"{IMG_PATH}/image*.jpeg")

        try:
            User.objects.create_superuser('sysop', '', 'sysop')
        except IntegrityError:
            pass

        with SAMPLE_PROJECTS_FILE.open() as f:
            for i, proj in enumerate(load_projects(json.load(f))):
                with transaction.atomic():
                    print(proj['slug'])
                    project = Project()
                    project.name = proj['name']
                    project.slug = proj['slug']
                    project.geom = proj['polygon']
                    project.center = proj['polygon'].centroid
                    f = (IMG_PATH / f"logo_{i + 1:04d}.jpeg").open("rb")
                    project.logo_file.save(f"logo{i + 1}.jpeg", File(f))
                    project.save()

                    for location_id in range(
                            self.num_of_locations_per_project):
                        location = Location()
                        location.project = project
                        location.name = silly.a_thing()
                        x0, y0, x1, y1 = project.geom.extent
                        x = random.uniform(x0, x1)
                        y = random.uniform(y0, y1)
                        location.point = Point(x, y)
                        location.information = silly.sentence()
                        location.save()

                        for photo_id in range(
                                random.randint(
                                    0, self.num_of_photos_per_location)):
                            photo = Photo()
                            photo.name = silly.a_thing()
                            photo.location = location
                            photo.date_taken = silly.datetime().date()
                            photo.lond_desc = silly.paragraph()
                            with open(random.choice(images), "rb") as f:
                                photo.photo_file.save("random.jpg", File(f))
                            photo.save()
Пример #8
0
def uc_main(howmany: int):
    pw = f'{silly.noun()}{silly.verb()}'

    userList = []
    for i in range(howmany):
        j = {
            "firstName": randFirstName(),
            "lastName": randLastName(),
            "password": pw,
            "title": silly.title(capitalize=True),
            "company": silly.company(capitalize=True),
            "address": silly.address(),
            "city": silly.city(),
            "country": silly.country(),
            "postal": silly.postal_code(),
            "email": silly.email(),
            "website": silly.domain(),
            "description": silly.sentence()
        }
        userList.append(j)

    for u in tqdm(userList, desc='user create'):
        create_user(u)
Пример #9
0
def get_paragraph(a, b):
    """
    Produces a paragraph of text with between a and b sentences.
    """
    return "\n".join([silly.sentence() for x in range(random.randint(a, b))])
Пример #10
0
def paragraph(length=6):
    return "\n".join([silly.sentence().title() for x in range(0, length)])
Пример #11
0
async def lets_get_silly():
    adj = silly.sentence()
    print(adj)
    await say(adj)
Пример #12
0
    credentials = pika.PlainCredentials(username='******', password='******')
    parameters = pika.ConnectionParameters("localhost", 32783, '/',
                                           credentials)
    connection = pika.BlockingConnection(parameters)
    channel = connection.channel()

    channel.queue_declare(queue=cfg.QUEUE_TOPIC)

    count_id += 1
    messType = ["100", "101", "102", "103", "200", "201", "202"]
    sr = SystemRandom()
    srType = sr.choice(messType)
    name = silly.thing()
    city = silly.city()
    company = silly.company()
    description = silly.sentence()
    data = {
        "id": count_id,
        "name": name,
        "city": city,
        "company": company,
        "description": description,
        "type": srType
    }
    message = json.dumps(data)
    channel.basic_publish(exchange='',
                          routing_key=cfg.QUEUE_TOPIC,
                          body=message)
    print(message)
    connection.close()
Пример #13
0
import silly
import requests
import mimetypes

image = silly.image()
print(image)
response = requests.head(image)
content_type = response.headers['content-type']
extension = mimetypes.guess_extension(content_type)
print(extension)
open('image.png', 'wb').write(requests.get(image).content)

print(silly.sentence())
Пример #14
0
def hello(s):
    print("Hello {}!".format(s))
    print(silly.sentence())