Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: cli useage updated in README.md #31

Merged
merged 6 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ conda install random-profile # using anaconda

## Documentation

### As Python Module

```python
from random_profile import RandomProfile
rp = RandomProfile(num=5)
Expand All @@ -39,7 +41,6 @@ rp = RandomProfile(num=5)
num = Total No. of Name You Want To Print
default is 1
change the num value according to your needs.

'''
# num can be overwritten in the function

Expand All @@ -56,9 +57,32 @@ rp.full_profile(num=10)
rp.last_name(num=6)
```

## Usage
### As Command Line Tool

```bash
random-profile --help
Usage: random-profile [OPTIONS]

usage: random_profile [-h] [-n N] [-f | -p | -l | -ip | -j]

optional arguments:
-h, --help show this help message and exit
-n N Number of random profiles
-f, --fullname Get full name instead of first name
-p, --profile Get full profile instead of first name
-l, --lastname Get last name instead of first name
-ip, --ipv4 Get an ipv4 IP address
-j, --jobtitle Get job title
```

```bash
random-profile -n 10 -f # to get 10 full names
random-profile -n 10 -p # to get 10 full profiles
random-profile -n 10 -l # to get 10 last names
random-profile -n 10 -ip # to get 10 ipv4 addresses
random-profile -n 10 -j # to get 10 job titles
```

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

## Support

Expand Down
22 changes: 12 additions & 10 deletions api/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import uvicorn
from fastapi import FastAPI, Depends
from fastapi.openapi.utils import get_openapi
Expand All @@ -12,14 +11,16 @@

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


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


@app.get('/api/v1/random_profile')
async def multiple_profile(params: query_model = Depends()):
""" Get multiple profile with all details

args:
num (int): number of profiles to generate
"""
Expand All @@ -34,10 +35,10 @@ async def multiple_profile(params: query_model = Depends()):
@app.get('/api/v1/random_profile/first_name')
async def multiple_first_name(params: query_model = Depends()):
""" Get multiple first names

args:
num (int): number of first names to generate

"""
params_as_dict = params.dict()
if params_as_dict['num'] > 100:
Expand All @@ -50,10 +51,10 @@ async def multiple_first_name(params: query_model = Depends()):
@app.get('/api/v1/random_profile/last_name')
async def multiple_last_name(params: query_model = Depends()):
""" Get multiple last names

args:
num (int): number of last names to generate

"""
params_as_dict = params.dict()
if params_as_dict['num'] > 100:
Expand All @@ -66,19 +67,20 @@ async def multiple_last_name(params: query_model = Depends()):
@app.get('/api/v1/random_profile/full_name')
async def multiple_full_name(params: query_model = Depends()):
""" Get multiple full names

args:
num (int): number of full names to generate

"""
params_as_dict = params.dict()
if params_as_dict['num'] > 100:
return {"status": "400", "message": "Number of profiles should be less than 100"}
num = params_as_dict['num']

full_names = rp.full_name(num)
return full_names


def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
Expand All @@ -98,4 +100,4 @@ def custom_openapi():
app.openapi = custom_openapi

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="0.0.0.0", port=8000)
2 changes: 1 addition & 1 deletion random_profile/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from random_profile.main import RandomProfile
from random_profile.main import RandomProfile
2 changes: 1 addition & 1 deletion random_profile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main():
elif args.ipv4:
print(*rp.ipv4(), sep="\n")
else:
print(*rp.first_name())
print('Type `random_profile -h` for help')


if __name__ == "__main__":
Expand Down
15 changes: 5 additions & 10 deletions random_profile/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
author : codeperfectplus
language : python 3.0 ++
github : codeperfectplus
______ __ ____ ____ __ ____ __
/ ____/____ ____/ /___ / __ \ ___ _____ / __/___ _____ / /_ / __ \ / /__ __ _____
/ / / __ \ / __ // _ \ / /_/ // _ \ / ___// /_ / _ \ / ___// __/ / /_/ // // / / // ___/
/ /___ / /_/ // /_/ // __/ / ____// __// / / __// __// /__ / /_ / ____// // /_/ /(__ )
\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/

'''

import os
Expand All @@ -31,6 +25,7 @@
cities_name_txt = os.path.join(ASSETS_DIR, "cities_name.txt")
states_names_txt = os.path.join(ASSETS_DIR, "states_names.txt")
job_titles_txt = os.path.join(ASSETS_DIR, "job_titles.txt")
email_domain_txt = os.path.join(ASSETS_DIR, "email_domains.txt")

# loading data from txt files
fname = load_txt_file(fname_txt)
Expand All @@ -42,6 +37,7 @@
street_names = load_txt_file(street_names_txt)
job_titles = load_txt_file(job_titles_txt)


class RandomProfile:
def __init__(self, num=1):
'''
Expand Down Expand Up @@ -84,8 +80,7 @@ def full_profile(self, num=None):
phone = f'+1-{random.randint(300, 500)}-{random.randint(800, 999)}-{random.randint(1000,9999)}'
job_title = random.choice(job_titles)
ip_address = ipv4_gen()
email_domain = random.choice(email_domains)


dob, age = generate_dob_age()
height, weight = generate_random_height_weight()

Expand Down Expand Up @@ -121,7 +116,7 @@ def full_profile(self, num=None):
def ipv4(self):
ip_list = [ipv4_gen() for _ in range(self.num)]
return ip_list

def job_title(self):
job_title_list = [random.choice(job_titles) for _ in range(self.num)]
return job_title_list
return job_title_list
29 changes: 16 additions & 13 deletions random_profile/utils.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
from datetime import datetime
import random
import os
import logging

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

import logging
logging.basicConfig(filename='log/example.log', encoding='utf-8', level=logging.DEBUG)


def load_txt_file(file_name: str) -> list:
""" function to load txt file into list

args:
file_name (str): file name to load

returns:
list: list of data from file
"""
with open(file_name, "r") as f:
data = f.read().splitlines()

basename = os.path.basename(file_name)
logging.debug(f"loaded {basename} with {len(data)} items")
return data


def ipv4_gen() -> str:
return f"{random.randint(0,255)}.{random.randint(0,255)}.{random.randint(0,255)}.{random.randint(0,255)}"


def generate_dob_age():
month = random.randint(1, 12)
if month == 2: # if month is feb
if month == 2: # if month is feb
day = random.randint(1, 28)
elif month in [4, 6, 9, 11]: # if month has 30 days
elif month in [4, 6, 9, 11]: # if month has 30 days
day = random.randint(1, 30)
elif month in [1, 3, 5, 7, 8, 10, 12]: # if month has 31 days
elif month in [1, 3, 5, 7, 8, 10, 12]: # if month has 31 days
day = random.randint(1, 31)

current_year = datetime.now().year
year = random.randint(current_year-80, current_year-18)
year = random.randint(current_year - 80, current_year - 18)

dob = datetime(day=day, month=month, year=year)
age = (datetime.now() - dob).days // 365
dob = dob.strftime("%d/%m/%Y")

return dob, age


def generate_random_height_weight():
height = random.randint(140, 200)
if height < 150:
Expand All @@ -58,4 +61,4 @@ def generate_random_height_weight():
weight = random.randint(80, 100)
elif height <= 200:
weight = random.randint(90, 110)
return height, weight
return height, weight
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Specifying that we are using markdown file for description
long_description_content_type="text/markdown",
# Any link to reach this module, if you have any webpage or github profile
data_files= [( 'assets', glob('random_profile/assets/*'))],
data_files=[('assets', glob('random_profile/assets/*'))],
url="https://github.com/codePerfectPlus/Random-Profile-Generator",
packages=setuptools.find_packages(),
# classifiers like program is suitable for python3, just leave as it is.
Expand Down
32 changes: 17 additions & 15 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import unittest
from random_profile import RandomProfile

import sys
sys.path.append('.')
from random_profile import RandomProfile

random_profile = RandomProfile(num=1)


class RandomProfileTest(unittest.TestCase):
def test_fname(self):
self.assertEqual(len(random_profile.first_name()), 1)

def test_faname_with_num(self):
self.assertEqual(len(RandomProfile(num=10).first_name()), 10)

def test_lname(self):
self.assertEqual(len(random_profile.last_name()), 1)

def test_lname_with_num(self):
self.assertEqual(len(RandomProfile(num=10).last_name()), 10)

def test_full_name(self):
self.assertEqual(len(random_profile.full_name()), 1)
def test_full_profile_with_num(self):
self.assertEqual(len(RandomProfile(num=10).full_profile()), 10)

def test_full_name_with_num(self):
self.assertEqual(len(RandomProfile(num=10).full_name()), 10)

def test_full_profile(self):
self.assertEqual(len(random_profile.full_profile()), 1)

def test_full_profile_with_num(self):
self.assertEqual(len(RandomProfile(num=10).full_profile()), 10)

def test_ipv4(self):
self.assertEqual(len(random_profile.ipv4()), 1)

def test_ipv4_with_num(self):
self.assertEqual(len(RandomProfile(num=10).ipv4()), 10)

def test_job_title(self):
self.assertEqual(len(random_profile.job_title()), 1)

def test_job_title_with_num(self):
self.assertEqual(len(RandomProfile(num=10).job_title()), 10)


if __name__ == "__main__":
unittest.main()
unittest.main()