Skip to content

Commit 4d51082

Browse files
authored
Merge pull request Py-Contributors#31 from codePerfectPlus/type-check
docs: cli useage updated in README.md
2 parents 9de5f25 + f290729 commit 4d51082

File tree

8 files changed

+80
-54
lines changed

8 files changed

+80
-54
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ conda install random-profile # using anaconda
3131

3232
## Documentation
3333

34+
### As Python Module
35+
3436
```python
3537
from random_profile import RandomProfile
3638
rp = RandomProfile(num=5)
@@ -39,7 +41,6 @@ rp = RandomProfile(num=5)
3941
num = Total No. of Name You Want To Print
4042
default is 1
4143
change the num value according to your needs.
42-
4344
'''
4445
# num can be overwritten in the function
4546

@@ -56,9 +57,32 @@ rp.full_profile(num=10)
5657
rp.last_name(num=6)
5758
```
5859

59-
## Usage
60+
### As Command Line Tool
61+
62+
```bash
63+
random-profile --help
64+
Usage: random-profile [OPTIONS]
65+
66+
usage: random_profile [-h] [-n N] [-f | -p | -l | -ip | -j]
67+
68+
optional arguments:
69+
-h, --help show this help message and exit
70+
-n N Number of random profiles
71+
-f, --fullname Get full name instead of first name
72+
-p, --profile Get full profile instead of first name
73+
-l, --lastname Get last name instead of first name
74+
-ip, --ipv4 Get an ipv4 IP address
75+
-j, --jobtitle Get job title
76+
```
77+
78+
```bash
79+
random-profile -n 10 -f # to get 10 full names
80+
random-profile -n 10 -p # to get 10 full profiles
81+
random-profile -n 10 -l # to get 10 last names
82+
random-profile -n 10 -ip # to get 10 ipv4 addresses
83+
random-profile -n 10 -j # to get 10 job titles
84+
```
6085

61-
the random-profile module is a random profile generator for many usages like: ex- fake dataset, YouTube videos, content creation, personal projects.
6286

6387
## Support
6488

api/api.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import uvicorn
32
from fastapi import FastAPI, Depends
43
from fastapi.openapi.utils import get_openapi
@@ -12,14 +11,16 @@
1211

1312
query_model = create_model("num", num=(int, ...))
1413

14+
1515
@app.get("/")
1616
def index():
1717
return {"status": "200", "message": "Welcome to Random Profile Generator API", "version": "0.2.3"}
1818

19+
1920
@app.get('/api/v1/random_profile')
2021
async def multiple_profile(params: query_model = Depends()):
2122
""" Get multiple profile with all details
22-
23+
2324
args:
2425
num (int): number of profiles to generate
2526
"""
@@ -34,10 +35,10 @@ async def multiple_profile(params: query_model = Depends()):
3435
@app.get('/api/v1/random_profile/first_name')
3536
async def multiple_first_name(params: query_model = Depends()):
3637
""" Get multiple first names
37-
38+
3839
args:
3940
num (int): number of first names to generate
40-
41+
4142
"""
4243
params_as_dict = params.dict()
4344
if params_as_dict['num'] > 100:
@@ -50,10 +51,10 @@ async def multiple_first_name(params: query_model = Depends()):
5051
@app.get('/api/v1/random_profile/last_name')
5152
async def multiple_last_name(params: query_model = Depends()):
5253
""" Get multiple last names
53-
54+
5455
args:
5556
num (int): number of last names to generate
56-
57+
5758
"""
5859
params_as_dict = params.dict()
5960
if params_as_dict['num'] > 100:
@@ -66,19 +67,20 @@ async def multiple_last_name(params: query_model = Depends()):
6667
@app.get('/api/v1/random_profile/full_name')
6768
async def multiple_full_name(params: query_model = Depends()):
6869
""" Get multiple full names
69-
70+
7071
args:
7172
num (int): number of full names to generate
72-
73+
7374
"""
7475
params_as_dict = params.dict()
7576
if params_as_dict['num'] > 100:
7677
return {"status": "400", "message": "Number of profiles should be less than 100"}
7778
num = params_as_dict['num']
78-
79+
7980
full_names = rp.full_name(num)
8081
return full_names
8182

83+
8284
def custom_openapi():
8385
if app.openapi_schema:
8486
return app.openapi_schema
@@ -98,4 +100,4 @@ def custom_openapi():
98100
app.openapi = custom_openapi
99101

100102
if __name__ == "__main__":
101-
uvicorn.run(app, host="0.0.0.0", port=8000)
103+
uvicorn.run(app, host="0.0.0.0", port=8000)

random_profile/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from random_profile.main import RandomProfile
1+
from random_profile.main import RandomProfile

random_profile/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def main():
5252
elif args.ipv4:
5353
print(*rp.ipv4(), sep="\n")
5454
else:
55-
print(*rp.first_name())
55+
print('Type `random_profile -h` for help')
5656

5757

5858
if __name__ == "__main__":

random_profile/main.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
author : codeperfectplus
44
language : python 3.0 ++
55
github : codeperfectplus
6-
______ __ ____ ____ __ ____ __
7-
/ ____/____ ____/ /___ / __ \ ___ _____ / __/___ _____ / /_ / __ \ / /__ __ _____
8-
/ / / __ \ / __ // _ \ / /_/ // _ \ / ___// /_ / _ \ / ___// __/ / /_/ // // / / // ___/
9-
/ /___ / /_/ // /_/ // __/ / ____// __// / / __// __// /__ / /_ / ____// // /_/ /(__ )
10-
\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/
11-
126
'''
137

148
import os
@@ -31,6 +25,7 @@
3125
cities_name_txt = os.path.join(ASSETS_DIR, "cities_name.txt")
3226
states_names_txt = os.path.join(ASSETS_DIR, "states_names.txt")
3327
job_titles_txt = os.path.join(ASSETS_DIR, "job_titles.txt")
28+
email_domain_txt = os.path.join(ASSETS_DIR, "email_domains.txt")
3429

3530
# loading data from txt files
3631
fname = load_txt_file(fname_txt)
@@ -42,6 +37,7 @@
4237
street_names = load_txt_file(street_names_txt)
4338
job_titles = load_txt_file(job_titles_txt)
4439

40+
4541
class RandomProfile:
4642
def __init__(self, num=1):
4743
'''
@@ -84,8 +80,7 @@ def full_profile(self, num=None):
8480
phone = f'+1-{random.randint(300, 500)}-{random.randint(800, 999)}-{random.randint(1000,9999)}'
8581
job_title = random.choice(job_titles)
8682
ip_address = ipv4_gen()
87-
email_domain = random.choice(email_domains)
88-
83+
8984
dob, age = generate_dob_age()
9085
height, weight = generate_random_height_weight()
9186

@@ -121,7 +116,7 @@ def full_profile(self, num=None):
121116
def ipv4(self):
122117
ip_list = [ipv4_gen() for _ in range(self.num)]
123118
return ip_list
124-
119+
125120
def job_title(self):
126121
job_title_list = [random.choice(job_titles) for _ in range(self.num)]
127-
return job_title_list
122+
return job_title_list

random_profile/utils.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
from datetime import datetime
22
import random
33
import os
4+
import logging
45

56
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
6-
7-
import logging
87
logging.basicConfig(filename='log/example.log', encoding='utf-8', level=logging.DEBUG)
98

9+
1010
def load_txt_file(file_name: str) -> list:
1111
""" function to load txt file into list
12-
12+
1313
args:
1414
file_name (str): file name to load
15-
15+
1616
returns:
1717
list: list of data from file
1818
"""
1919
with open(file_name, "r") as f:
2020
data = f.read().splitlines()
21-
21+
2222
basename = os.path.basename(file_name)
2323
logging.debug(f"loaded {basename} with {len(data)} items")
2424
return data
2525

26+
2627
def ipv4_gen() -> str:
2728
return f"{random.randint(0,255)}.{random.randint(0,255)}.{random.randint(0,255)}.{random.randint(0,255)}"
2829

30+
2931
def generate_dob_age():
3032
month = random.randint(1, 12)
31-
if month == 2: # if month is feb
33+
if month == 2: # if month is feb
3234
day = random.randint(1, 28)
33-
elif month in [4, 6, 9, 11]: # if month has 30 days
35+
elif month in [4, 6, 9, 11]: # if month has 30 days
3436
day = random.randint(1, 30)
35-
elif month in [1, 3, 5, 7, 8, 10, 12]: # if month has 31 days
37+
elif month in [1, 3, 5, 7, 8, 10, 12]: # if month has 31 days
3638
day = random.randint(1, 31)
37-
39+
3840
current_year = datetime.now().year
39-
year = random.randint(current_year-80, current_year-18)
40-
41+
year = random.randint(current_year - 80, current_year - 18)
42+
4143
dob = datetime(day=day, month=month, year=year)
4244
age = (datetime.now() - dob).days // 365
4345
dob = dob.strftime("%d/%m/%Y")
44-
46+
4547
return dob, age
4648

49+
4750
def generate_random_height_weight():
4851
height = random.randint(140, 200)
4952
if height < 150:
@@ -58,4 +61,4 @@ def generate_random_height_weight():
5861
weight = random.randint(80, 100)
5962
elif height <= 200:
6063
weight = random.randint(90, 110)
61-
return height, weight
64+
return height, weight

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Specifying that we are using markdown file for description
2020
long_description_content_type="text/markdown",
2121
# Any link to reach this module, if you have any webpage or github profile
22-
data_files= [( 'assets', glob('random_profile/assets/*'))],
22+
data_files=[('assets', glob('random_profile/assets/*'))],
2323
url="https://github.com/codePerfectPlus/Random-Profile-Generator",
2424
packages=setuptools.find_packages(),
2525
# classifiers like program is suitable for python3, just leave as it is.

tests/test_package.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
import unittest
2+
from random_profile import RandomProfile
3+
24
import sys
35
sys.path.append('.')
4-
from random_profile import RandomProfile
56

67
random_profile = RandomProfile(num=1)
78

9+
810
class RandomProfileTest(unittest.TestCase):
911
def test_fname(self):
1012
self.assertEqual(len(random_profile.first_name()), 1)
11-
13+
1214
def test_faname_with_num(self):
1315
self.assertEqual(len(RandomProfile(num=10).first_name()), 10)
14-
16+
1517
def test_lname(self):
1618
self.assertEqual(len(random_profile.last_name()), 1)
17-
19+
1820
def test_lname_with_num(self):
1921
self.assertEqual(len(RandomProfile(num=10).last_name()), 10)
20-
22+
2123
def test_full_name(self):
2224
self.assertEqual(len(random_profile.full_name()), 1)
23-
24-
def test_full_profile_with_num(self):
25-
self.assertEqual(len(RandomProfile(num=10).full_profile()), 10)
26-
25+
26+
def test_full_name_with_num(self):
27+
self.assertEqual(len(RandomProfile(num=10).full_name()), 10)
28+
2729
def test_full_profile(self):
2830
self.assertEqual(len(random_profile.full_profile()), 1)
29-
31+
3032
def test_full_profile_with_num(self):
3133
self.assertEqual(len(RandomProfile(num=10).full_profile()), 10)
32-
34+
3335
def test_ipv4(self):
3436
self.assertEqual(len(random_profile.ipv4()), 1)
35-
37+
3638
def test_ipv4_with_num(self):
3739
self.assertEqual(len(RandomProfile(num=10).ipv4()), 10)
3840

3941
def test_job_title(self):
4042
self.assertEqual(len(random_profile.job_title()), 1)
41-
43+
4244
def test_job_title_with_num(self):
4345
self.assertEqual(len(RandomProfile(num=10).job_title()), 10)
44-
46+
4547

4648
if __name__ == "__main__":
47-
unittest.main()
49+
unittest.main()

0 commit comments

Comments
 (0)