Example #1
0
def main():

    animal_head_list = ['snake', 'bull', 'lion', 'raven', 'bunny']

    bizarre_animals = {}
    bizarre_animals['animals'] = []

    for x in range(20):

        head = animal_head_list[random.randint(0, 4)]

        body1 = petname.name()
        body2 = petname.name()
        body = body1 + '-' + body2

        num_arms = random.randrange(2, 11, 2)

        num_legs = random.randrange(3, 13, 3)

        num_tails = num_arms + num_legs

        bizarre_animals['animals'].append({
            'head': head,
            'body': body,
            'arms': num_arms,
            'legs': num_legs,
            'tails': num_tails
        })

    with open('animals.json', 'w') as out:
        json.dump(bizarre_animals, out, indent=2)
def main():
    animal_dict = {}
    animal_dict['animals'] = []
    head = ['snake', 'bull', 'lion', 'raven', 'bunny']

    for i in range(20):
        arms = random.randrange(2,11,2)
        legs = random.randrange(3,13,3)
        tail = arms + legs
        body1 = petname.name()
        body2 = petname.name()
    
        while (body1 == body2):
            body2 = petname.name()

        body = body1 + "-" + body2

        created_on = str(datetime.datetime.now())
        uid = str(uuid.uuid4())

        animal_dict['animals'].append({'head': head[random.randrange(0,5,1)], 'body': body, 'arms': arms, 'legs': legs, 'tail' : tail, 'created_on': created_on,'uuid': uid})

    rd = redis.StrictRedis(host='127.0.0.1', port=6420, db=0)
    rd.set('animals', json.dumps(animal_dict, indent=2))
    print(json.loads(rd.get('animals')))
Example #3
0
def generate_data(entries_count):
    values = []
    index_id = 0
    for x in range(entries_count):
        index_id = index_id + 1
        if (fake.pybool()):
            value = dict(id=index_id,
                         firstName=fake.first_name_male(),
                         lastName=fake.last_name_male(),
                         age=random.randint(18, 60),
                         employment=fake.job().replace("'", ''),
                         location=fake.city().replace("'", ''),
                         favoriteColor=fake.color_name(),
                         petName=petname.name().title(),
                         serverId=server_id,
                         addTimestamp=datetime.datetime.now().strftime(
                             '%Y-%b-%d %H:%M:%S'))
            values.append(value)
        else:
            value = dict(id=index_id,
                         firstName=fake.first_name_female(),
                         lastName=fake.last_name_female(),
                         age=random.randint(18, 60),
                         employment=fake.job().replace("'", ''),
                         location=fake.city().replace("'", ''),
                         favoriteColor=fake.color_name(),
                         petName=petname.name().title(),
                         serverId=server_id,
                         addTimestamp=datetime.datetime.now().strftime(
                             '%Y-%b-%d %H:%M:%S'))
            values.append(value)
    return values
Example #4
0
def delete_database():

    rd.flushdb()

    for i in range(20):

        start_date = datetime.date(2001, 7, 24)
        end_date = datetime.date(2021, 7, 24)
        difference = end_date - start_date
        days_between = difference.days
        random_num_days = random.randrange(days_between)

        my_animal = {}
        unique_Id = str(uuid.uuid4())
        my_animal['head'] = random.choice(
            ['snake', 'bull', 'lion', 'raven', 'bunny'])
        my_animal['body'] = petname.name() + '-' + petname.name()
        my_animal['arms'] = random.randint(1, 5) * 2
        my_animal['legs'] = random.randint(1, 4) * 3
        my_animal['tail'] = my_animal['legs'] + my_animal['arms']
        my_animal['created: '] = str(start_date +
                                     datetime.timedelta(days=random_num_days))

        rd.set(unique_Id, json.dumps(my_animal))

    return 'Success'
Example #5
0
def gen_body():
    animal_1 = petname.name()
    animal_2 = petname.name()

    while (animal_1 == animal_2):
        animal2 = petname.name()

    return animal_1 + '-' + animal_2
def generate_body():
    animal1 = petname.name()
    animal2 = petname.name()

    while (animal1 == animal2):
        animal2 = petname.name()

    return animal1 + '-' + animal2
Example #7
0
def generate_random():
    head_choices = ['snake', 'bull', 'lion', 'raven', 'bunny']
    random_animal = {}
    random_animal['head'] = head_choices[random.randint(0,4)]
    random_animal['body'] = petname.name() + '-' + petname.name()
    random_animal['arms'] = random.randrange(2,11,2)
    random_animal['legs'] = random.randrange(3,13,3)
    random_animal['tails'] = random_animal['arms'] + random_animal['legs']
    return random_animal
Example #8
0
def generate_random():
    head_choices = ['snake', 'bull', 'lion', 'raven', 'bunny']
    random_animal = {}
    random_animal['head'] = head_choices[random.randint(0, 4)]
    random_animal['body'] = petname.name() + '-' + petname.name()
    random_animal['arms'] = random.randrange(2, 11, 2)
    random_animal['legs'] = random.randrange(3, 13, 3)
    random_animal['tails'] = random_animal['arms'] + random_animal['legs']
    random_animal['creation time'] = str(datetime.datetime.now())
    random_animal['uid'] = str(uuid.uuid4())
    return random_animal
Example #9
0
def main():
    heads = ['snake', 'bull', 'lion', 'raven', 'bunny']
    animals = []
    for i in range(20):
        animal = {}
        animal['head'] = heads[random.randint(0,4)]
        animal['body'] = petname.name() + '-' + petname.name()
        animal['arms'] = random.randint(2, 10)
        animal['legs'] = random.randint(3, 12)
        animal['tails'] = animal['arms'] + animal['legs']
        animals.append(animal)
    with open('animals.json', 'w', encoding='utf-8') as f:
        json.dump({'animals': animals}, f, ensure_ascii=False, indent=4)
Example #10
0
def generate_animals():
    for i in range(20):
        head = random.choice(['snake', 'bull', 'lion', 'raven', 'bunny'])
        body = petname.name() + '-' + petname.name()
        arms = random.randint(1,5) * 2
        legs = random.randint(1,4) * 3
        tail = legs + arms
        created_on = str(datetime.now())
        uid = str(uuid.uuid4())

        rd.hmset(uid, {'head' : head, 'body' : body, 'arms' : arms, 'legs' : legs, 'tail' : tail, 'created_on' : created_on})

    return "Animals generated \n"
Example #11
0
def generate():

    for i in range(20):
        this_animal = {}
        this_animal['head'] = random.choice(
            ['snake', 'bull', 'lion', 'raven', 'bunny'])
        this_animal['body'] = petname.name() + '-' + petname.name()
        this_animal['arms'] = random.randint(1, 5) * 2
        this_animal['legs'] = random.randint(1, 4) * 3
        this_animal['tail'] = this_animal['legs'] + this_animal['arms']
        this_animal['created_on'] = str(datetime.datetime.now())

        rd.hmset(str(uuid.uuid4()), this_animal)

    return '20 animals have been generated'
Example #12
0
def main():

    animal_dict = {}
    animal_dict['animals'] = []

    for i in range(20):
        this_animal = {}
        this_animal['head'] = random.choice(
            ['snake', 'bull', 'lion', 'raven', 'bunny'])
        this_animal['body'] = petname.name() + '-' + petname.name()
        this_animal['arms'] = random.randint(1, 5) * 2
        this_animal['legs'] = random.randint(1, 4) * 3
        this_animal['tail'] = this_animal['legs'] + this_animal['arms']

        animal_dict['animals'].append(this_animal)

    with open(sys.argv[1], 'w') as f:
        json.dump(animal_dict, f, indent=2)
def main():
    # rd = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
    heads = ['snake', 'bull', 'lion', 'raven', 'bunny']
    animals = []
    for i in range(20):
        animal = {}
        animal['uid'] = str(uuid.uuid4())
        animal['head'] = heads[random.randint(0, 4)]
        animal['body'] = petname.name() + '-' + petname.name()
        animal['arms'] = random.randint(2, 10)
        animal['legs'] = random.randint(3, 12)
        animal['tails'] = animal['arms'] + animal['legs']
        animal['created_on'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
        animals.append(animal)
        time.sleep(1)
        # rd.hmset(uid, animal)
    with open('./data/data_file.json', 'w', encoding='utf-8') as f:
        json.dump({'animals': animals}, f, ensure_ascii=False, indent=4)
Example #14
0
def animals_reset():
    animal_dict = {}
    animal_dict['animals'] = []

    for i in range(20):
        this_animal = {}
        this_animal['head'] = random.choice(
            ['snake', 'bull', 'lion', 'raven', 'bunny'])
        this_animal['body'] = petname.name() + '-' + petname.name()
        this_animal['arms'] = random.randint(1, 5) * 2
        this_animal['legs'] = random.randint(1, 4) * 3
        this_animal['tail'] = this_animal['legs'] + this_animal['arms']
        this_animal['created_on'] = str(datetime.datetime.now())
        this_animal['uuid'] = str(uuid.uuid4())

        animal_dict['animals'].append(this_animal)

    rd.set('animals', json.dumps(animal_dict, indent=2))
    return str('success')
Example #15
0
async def chat_handler(request):
    login = request.cookies.get('login', petname.name())
    context = {
        'people':
        set([login for login in request.app['websockets']] + [login]),
        'notify': f'{login} joined to chat',
    }
    response = aiohttp_jinja2.render_template('chat.html', request, context)
    response.cookies['login'] = login
    return response
def main():
    animal_dict = {}
    animal_dict['animals'] = []
    head = ['snake', 'bull', 'lion', 'raven', 'bunny']

    for i in range(20):
        arms = random.randrange(2,11,2)
        legs = random.randrange(3,13,3)
        tail = arms + legs
        body1 = petname.name()
        body2 = petname.name()
    
        while (body1 == body2):
            body2 = petname.name()

        body = body1 + "-" + body2

        animal_dict['animals'].append({'head': head[random.randrange(0,5,1)], 'body': body, 'arms': arms, 'legs': legs, 'tail' : tail})

    with open(sys.argv[1],'w') as f:
        json.dump(animal_dict, f, indent=2)
Example #17
0
def main():

    rd = redis.StrictRedis(host='127.0.0.1', port=6406, db=0)

    for i in range(20):
        head = random.choice(['snake', 'bull', 'lion', 'raven', 'bunny'])
        body = petname.name() + '-' + petname.name()
        arms = random.randint(1, 5) * 2
        legs = random.randint(1, 4) * 3
        tail = legs + arms
        created_on = str(datetime.datetime.now())
        uid = str(uuid.uuid4())

        rd.hmset(
            uid, {
                'head': head,
                'body': body,
                'arms': arms,
                'legs': legs,
                'tail': tail,
                'created_on': created_on
            })
Example #18
0
async def ws_handler(request):

    ws = web.WebSocketResponse()
    await ws.prepare(request)

    login = request.cookies.get('login', petname.name())
    request.app['websockets'].update({login: ws})

    for _, ws_ in request.app['websockets'].items():
        if ws is not ws_:
            await ws_.send_str(
                json.dumps({
                    'people_list':
                    aiohttp_jinja2.render_string(
                        'people_list.html', request, {
                            'people_list':
                            [login for login in request.app['websockets']]
                        }),
                    'notify':
                    aiohttp_jinja2.render_string(
                        'notify.html', request,
                        {'notify': f'{login} joined to chat'}),
                }))

    # TODO: проработать корректное закрытие сокета
    try:
        async for msg in ws:
            if msg.type == aiohttp.WSMsgType.TEXT:
                for _, ws_ in request.app['websockets'].items():
                    await ws_.send_str(
                        json.dumps({
                            'message':
                            aiohttp_jinja2.render_string(
                                'message.html', request, {
                                    'login':
                                    login,
                                    'message':
                                    msg.data,
                                    'time':
                                    str(datetime.datetime.now().strftime(
                                        "%Y-%m-%d %H:%M:%S"))
                                })
                        }))
            elif msg.type == aiohttp.WSMsgType.ERROR:
                pass
    except:
        ws.close()
    finally:
        del request.app['websockets'][login]

    return ws
Example #19
0
def establish_database():
    rd = redis.StrictRedis(host='redis', port=6379, db=8)
    animal_head_list = ['snake', 'bull', 'lion', 'raven', 'bunny']
    for x in range(100):
        head = animal_head_list[random.randint(0, 4)]
        body1 = petname.name()
        body2 = petname.name()
        body = body1 + '-' + body2
        num_arms = random.randrange(2, 11, 2)
        num_legs = random.randrange(3, 13, 3)
        num_tails = num_arms + num_legs
        timestamp = str(datetime.datetime.now())
        animal = {}
        animal['head'] = head
        animal['body'] = body
        animal['arms'] = num_arms
        animal['legs'] = num_legs
        animal['tails'] = num_tails
        animal['creation time'] = timestamp
        animal['uid'] = str(uuid.uuid4())
        rd.hmset(x, animal)

    return "fresh database"
Example #20
0
arms = []
for i in range(2, 11, 2):
    arms.append(i)

legs = []
for i in range(3, 13, 3):
    legs.append(i)

dict_animals['animals'] = []

for i in range(1, 21, 1):

    heads = ['snake', 'bull', 'lion', 'raven', 'bunny']
    ran_head = random.choice(heads)

    ani = petname.name()
    ani2 = petname.name()
    bodies = ani + ' ' + ani2

    ran_arm = random.choice(arms)

    ran_leg = random.choice(legs)

    tails = ran_arm + ran_leg

    dict_animals['animals'].append({
        'head': ran_head,
        'body': bodies,
        'arms': ran_arm,
        'legs': ran_leg,
        'tails': tails
Example #21
0
import json, petname, random, sys
''' Initialize list "head_choices" with the five animal head choices: '''

head_choices = ["snake", "bull", "lion", "raven", "bunny"]
animal_list = [
]  # Initialize data structure to contain dictionaries of animals

for i in range(0, 20):
    ''' Invoke "random()" method to randomly generate one of the head choices: '''

    head_type = head_choices[random.randint(0, 4)]
    ''' Invoke "name()" method to randomly generate two animal strings for                                                                                                                                                                  
    the two body components: '''

    body_comp_1 = petname.name()
    body_comp_2 = petname.name()
    ''' Employ "while loop" to ensure that the two components of the body                                                                                                                                                                   
    are not identical '''

    while (body_comp_1 == body_comp_2):
        body_comp_2 = petname.name()
    ''' Generate a random even number of arms between 2 and 10 inclusive: '''

    arms_number = random.randint(2, 10)
    ''' Employ "while loop" to ensure that the number of arms meets the                                                                                                                                                                     
    aforementioned criteria: '''

    while ((arms_number % 2) > 0):
        arms_number = random.randint(2, 10)
    ''' Generate a random number of legs that is both a multiple of three and                                                                                                                                                               
def main():

    ''' Initialize list "head_choices" with the five animal head choices: '''

    head_choices = ["snake", "bull", "lion", "raven", "bunny"]
    animal_list = [] # Initialize data structure to contain dictionaries of animals                                                                                                                                                                                           

    for i in range(0,20):

        ''' Invoke "random()" method to randomly generate one of the head choices: '''

        head_type = head_choices[random.randint(0,4)]

        ''' Invoke "name()" method to randomly generate two animal strings for                                                                                                                                                                                                
        the two body components: '''

        body_comp_1 = petname.name()
        body_comp_2 = petname.name()

        ''' Employ "while loop" to ensure that the two components of the body                                                                                                                                                                                                 
        are not identical '''

        while (body_comp_1 == body_comp_2):
            body_comp_2 = petname.name()

        ''' Generate a random even number of arms between 2 and 10 inclusive: '''

        arms_number = random.randint(2,10)

        ''' Employ "while loop" to ensure that the number of arms meets the                                                                                                                                                                                                   
        aforementioned criteria: '''

        while ((arms_number % 2) > 0):
            arms_number = random.randint(2,10)

        ''' Generate a random number of legs that is both a multiple of three and                                                                                                                                                                                             
        between the numbers 3, and 12 inclusive: '''

        legs_number = random.randint(3,12)

        ''' Employ "while loop" to ensure that the number of legs meets the                                                                                                                                                                                                   
        aforementioned criteria: '''

        while ((legs_number % 3) != 0):
            legs_number = random.randint(3,12)


        ''' Append a non-random number of tails that is equal to the sum of the     
        
        number of arms and legs: '''

        tails_num = arms_number + legs_number

        animal_list.append({'head': head_type, \
                            'body': body_comp_1 + "-" + body_comp_2, \
                                'arms': arms_number, 'legs': legs_number, \
                                    'tails': tails_num})

    ''' Insert the list of dictionaries data structure "animal_list" into a                        
    dictionary to create an exportable JSON object: '''

    animal_struct = {'animals': animal_list}

    ''' Use the JSON library to dump the data structure into a json file whose file name is read i\
n from the terminal": '''

    with open(sys.argv[1], 'w') as out:

      json.dump(animal_struct, out, indent=2)
Example #23
0
rd=redis.StrictRedis(host='127.0.0.1',port=6391, db=0)

# generate animals 
head_generator = ['bull', 'lion', 'raven', 'bunny']
arm_generator = [2,4,6,8,10]
leg_generator = [3,6,9,12]
animals = {}

for i in range (20):
   uid = str(uuid.uuid4())
   animals[uid] = {}
   today = datetime.date.today()
   animals[uid]['created_on'] =str(today)
   animals[uid]['head'] = random.choice(head_generator)
   
   body1 = petname.name()
   body2 = petname.name()
   animals[uid]['body'] = ('{}-{}').format(body1, body2)

   animals[uid]['arms'] = random.choice(arm_generator)
   animals[uid]['legs'] = random.choice(leg_generator)
   animals[uid]['tail'] = animals[uid]['arms']+animals[uid]['legs']
   
# upload to redis database
for i in animals:
   key = str(i)
   value = animals[i]
   rd.hmset(key,value)

# upload to json file
with open('animals.json', 'w') as out:
Example #24
0
import json
import petname
from random import randrange

head_list = ['snake', 'bull', 'lion', 'raven', 'bunny']

data = {}
data['animals'] = []
for i in range(20):
    a = randrange(2, 11, 2)
    l = randrange(3, 13, 3)
    data['animals'].append({
        'head': head_list[randrange(1, 5, 1)],
        'body': petname.name() + '-' + petname.name(),
        'arms': a,
        'legs': l,
        'tail': a + l
    })

with open('animals.json', 'w') as out:
    json.dump(data, out, indent=2)
Example #25
0
 def test_len(self):
     for l in range(4, 10):
         self.assertLessEqual(len(petname.name(l)), l)
Example #26
0
def choose_body():
    name1 = petname.name()
    name2 = petname.name()

    return name1 + '-' + name2
Example #27
0
 def test_works(self):
     self.assertIn(petname.name(), petname.english.names)
Example #28
0
def make_body():
    body1 = petname.name()
    body2 = petname.name()
    body = body1 + "-" + body2
    return body
Example #29
0
	def test_works(self):
		self.assertIn(petname.name(), petname.english.names)
Example #30
0
	def test_len(self):
		for l in range(4, 10):
			self.assertLessEqual(len(petname.name(l)), l)
Example #31
0
import petname
import json
import random

data={}
heads=['snake', 'bull', 'lion', 'raven', 'bunny']

data['animals']=[]

for i in range(20):
	head=heads[random.randint(0,3)]
	body=petname.name()+"-"+petname.name()
	arms=random.randrange(2,11,2)
	legs=random.randrange(3,13,3)
	tails=arms+legs
	data['animals'].append({'head':head, 'body':body, 'arms':arms, 'legs':legs, 'tails':tails})

with open ('animals.json', 'w') as out:
	json.dump(data,out,indent=2)