Beispiel #1
0
def step2_mokc_data():  #using environment variables
    xx = traverse_replace_yaml_tree(yaml_config)
    xx = recurse_replace_yaml(xx, runtime_dict)
    for project in xx:

        incoming = xx[project]['incoming']
        outgoing = xx[project]['outgoing']
        logger = logging.getLogger()
        pio = ProjectIO(project=project,
                        logger=logger,
                        incoming=incoming,
                        outgoing=outgoing)

        os.makedirs(pio.incoming.path, exist_ok=True)
        os.makedirs(pio.outgoing.path, exist_ok=True)
        #print(yaml_reader('/workspace/scripts/switchboard.yaml'))
        lorem = TextLorem(wsep='_', srange=(2, 3))
        for i in range(MOCKSIZE):

            file_name = lorem.sentence() + random.choice(FILE_TYPES)
            with open(os.path.join(pio.incoming.path, file_name), 'a') as f:
                f.write(lorem.paragraph())
            os.chmod(os.path.join(pio.incoming.path, file_name), 0o777)
    def test_02_make_dirs(self):  #using environment variables

        for project in yaml_config:

            incoming = yaml_config[project]['incoming']
            outgoing = yaml_config[project]['outgoing']
            logger = logging.getLogger()
            pio = ProjectIO(project=project,
                            logger=logger,
                            incoming=incoming,
                            outgoing=outgoing)

            os.makedirs(os.path.abspath(pio.incoming.path), exist_ok=True)
            os.makedirs(os.path.abspath(pio.outgoing.path), exist_ok=True)
            #print(yaml_reader('/workspace/scripts/switchboard.yaml'))
            lorem = TextLorem(wsep='_', srange=(2, 3))
            for i in range(10):

                file_name = lorem.sentence() + random.choice(FILE_TYPES)
                with open(os.path.join(pio.incoming.path, file_name),
                          'a') as f:
                    f.write(lorem.paragraph())
                os.chmod(os.path.join(pio.incoming.path, file_name), 0o777)
Beispiel #3
0
def seed_database():
    print('seeding db')
    bcrypt = Bcrypt()
    title_lorem = TextLorem(wsep=" ", srange=(2, 10))
    content_lorem = TextLorem(wsep=" ", srange=(10, 20))
    # current user in database
    password = b'ava_utf8'
    hashed_password = bcrypt.generate_password_hash(password).decode("utf-8")
    ava = User(
        username='******',
        password=hashed_password,
        email='*****@*****.**',
        first_name='Ava',
        last_name='Ava',
        profile_photo=
        'https://images.unsplash.com/photo-1521191809347-74bcae21439c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=60'
    )

    print('adding user')
    db.session.add(ava)
    db.session.commit()

    # seed chirps
    chirps = []
    for _ in range(6):
        chirp = Feedback(title=title_lorem.sentence(),
                         content=content_lorem.paragraph(),
                         username='******')
        chirps.append(chirp)

    # add list of chirps to psql
    print('adding chirps')
    db.session.bulk_save_objects(chirps)
    db.session.commit()

    print('chirps added')
Beispiel #4
0
from lorem.text import TextLorem

# remove duplicate entries from the list of topics
with open("topics.txt", "w") as topics:
    lines_seen = set()  # holds lines already seen
    for line in open("topics_w_dups.txt", "r"):
        if line not in lines_seen:  # not a duplicate
            topics.write(line)
            lines_seen.add(line)

# make an insert statement for each topic
with open("topics.txt", "r") as topics:
    sql = open("../../sql/insert/topics.sql", "w")
    # 4-16 words/sentence, 2-16 sentences/paragraph
    lorem = TextLorem(srange=(4, 16), prange=(2, 16))
    for topic in topics:
        while True:
            description = lorem.paragraph()
            # ensure the description fits in db
            if len(description) <= 255:
                break
        # remove trailing \n and escape single quotes
        label = topic[:-1].replace("'", "''")
        sql.write("""
insert into topics
	(label, description)
values
	('""" + label + "', '" + description + """');
""")
    sql.close()
Beispiel #5
0
# loop for all of time
while True:
    # new lorem instance for random text
    lorem = TextLorem()

    # a block of random text to go in the email body
    t1 = lorem.text()

    # set the subject to something unique so we don't end up with
    email_subject = "Hello from {}".format(lorem.sentence())

    email_body = "MIME-Version: 1.0\nContent-type: text/html\nFrom: {efrom}\nTo: {to}\nSubject: {subject}\n\n<b>Hi. This is a randomly-generated message.</b>\n<p>Really, all I'm doing is trying to generate some email for these mailboxes, and keep it continuously flowing.\n<p>This is really just for continuous testing - for before/during/after migration scenarios.\n<p>Here's some random text:\n\n{ipsum}".format(
        efrom=email_sender,
        to=body_recipients,
        subject=email_subject,
        ipsum=lorem.paragraph())

    server = smtplib.SMTP(mail_server)
    server.starttls()
    server.login(email_sender, email_password)
    server.ehlo()
    server.sendmail(email_sender, email_recipients, email_body)
    server.close()

    print('Email sent successfully.')

    # generate a random integer
    sleeptime = randint(60, 300)

    # convert it to human-readable
    print("Sleeping for {}".format(str(datetime.timedelta(seconds=sleeptime))))