Archive
Python: My Fake Data Generator P-5
Learning : Python: Functions, Procedures and documentation
Subject: About fake data P-5: (Fake Animal list)
Although I call this a Fake Animals list, but the names are for real animals, I am creating a json file fill of animals, each has name and type, also I add a key called information where I am giving a short summary about the data-set. Also I upload the data-set to my account in GitHub, so we can load the json file using Python requests library. The data-set will be updated frequently by adding more animals.
Standarizing: I will try to create all my data-sets with a standard information key, this key will show the following:
- Date: Will show the data-set crating date.
- Last Update: Will show the last update of the data-set file.
- Creator: Will be my name.
- Desc: Is a short description about the data-set.
- Legal: Is the copyright and the limits of using this data-set
To access this part of the data set you can run this code ..
# Function to print-out the information key in the data-set
def get_info(adata):
print('\n Information about Creatures data-set.')
for each in adata['information']:
for k in each.keys():
print(' ', k + ": " + each[k])
Creatures data-set:This data set is containing the name of animals and their types, animal types are: mammals | insects | birds | reptiles. Our function def get_animals() will take three arguments: the data, the type of animal we want and the size, and it will return a list of animals names.
Here is the code. .
# Function return a list of random animals names.
def get_animals(adata, atype, dsize):
"""
Date: 17/12/2019
Creator : Ali Radwani
Function to return X numbers of animal names. The data-set contain animals with
four categories:
- Mammals
- Birds
- Insect
- Reptiles
:param : dict: adata:
:param : str: atype:
:param : int: dsize:
:return: list : t_names
"""
t_names = []
t_ind_list = get_type_index(adata,atype)
t_size = len(t_ind_list)
if dsize < t_size:
for x in range (dsize):
t_names.append(data['animals'][random.choice(t_ind_list)]['name'])
else:
print('\n The {} data-set is less than data size you ask for. Maximum size is {} {}.'.format(atype,t_size,atype))
return t_names
|
And here is the out-put ..
|
:: Fake Function List ::
| Function Name | Description |
| Color | To return a random color code in RGB or Hex. |
| Date | To return a random date. |
| Mobile | To return a mobile number. |
| Country | To return a random country name. |
| City | To return a random City name. |
| ID | To return X random dig as ID. |
| Time | To return random time. |
| Car’s Brand | |
| file_name | file name: list for fake file names. |
| Creatures | Random animal names of a certain type: Mammals, Birds, Insect, Reptiles |
| Done |
By: Ali Radwani


Follow me on Twitter..

