diff --git a/README.md b/README.md index 48cbf4a..cb8acf6 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,28 @@ print(cpf) rg = fake.rg() print(rg) -# MG86103044 +# 86103044 + +rg = fake.rg(is_complete=True) +print(rg) +#{ +# 'name':'Lucimara Santos Lemos', +# 'gender': 'F', +# 'birth': { +# 'day': '21/10/1954', +# 'cite':'Pocos de Caldas', +# 'state':'MG' +# }, +# 'org': { +# 'name': 'PC', +# 'state': 'MG', +# }, +# 'affiliation': { +# 'father': 'Ronaldo Castro Lemos', +# 'mother': 'Sophia Santos Lemos' +# }, +# 'rg': MG88103067 +# } crm = fake.crm() print(crm) diff --git a/pyFBIG/BR_names/name.py b/pyFBIG/BR_names/name.py index be009a6..2efd8d1 100644 --- a/pyFBIG/BR_names/name.py +++ b/pyFBIG/BR_names/name.py @@ -29,7 +29,10 @@ def surname(self): def gen_name(self, is_complete: bool = False): rand_list: list = [self.gen_female_name(), self.gen_male_name()] _index = randrange(0, 2) + gender: str = "M" _name = rand_list[_index] + if _index < 1: + gender = 'F' if is_complete == False: return _name else: @@ -40,7 +43,7 @@ def gen_name(self, is_complete: bool = False): rand_surname: str = self.gen_surname() if surnames[0] != rand_surname: surnames.append(rand_surname) - return _name + ' '+ surnames[0] + ' ' + surnames[1] + return {'name': _name + ' '+ surnames[0] + ' ' + surnames[1], 'gender': gender} def gen_female_name(self): female_name = self.female_name() diff --git a/pyFBIG/fake_br_id.py b/pyFBIG/fake_br_id.py index 24bd4b4..859093a 100644 --- a/pyFBIG/fake_br_id.py +++ b/pyFBIG/fake_br_id.py @@ -47,8 +47,13 @@ def crm(self, especial_char: bool = True, return_list: bool = False, is_complete def rg(self, is_complete: bool= False): """ RG (Registro Geral) generation call function: + + Args: + is_complete: Defines whether it will return a simple string containing just an RG number or + whether it will return a dictionary containing all information present in an RG + Returns: - Returns the generated RG numbers in string format. + Returns the generated RG fake data. It can return a string format (if is_complete is false) or a dictionary (if is_complete is True). """ rg_gen: Type[IGenerator] = RGGenerator() rg_gen.is_complete = is_complete diff --git a/pyFBIG/igen_product.py b/pyFBIG/igen_product.py index 552d419..52a7df6 100644 --- a/pyFBIG/igen_product.py +++ b/pyFBIG/igen_product.py @@ -8,6 +8,32 @@ def __init__(self): def rand_num(self) -> int: return randrange(0, 9) + def rand_birthday(self) -> str: + year: int = randrange(1920, 2023) + month: int = randrange(0, 12) + month_31days: list = [1,3,5,7,8,10,12] + day_range: int # Variable that determines the maximum number of days the month will have + + if month in month_31days: # Determines the maximum number of days the month will have. + day_range = 31 + elif month == 2: # Determines if the year is a leap year to adjust the maximum February days + if type(year/4) == float and type(year/400) == float or type(year/100) == int: + day_range = 28 + else: + day_range = 29 + else: + day_range = 30 + day: int = randrange(0, day_range) + + birthday: list = [day, month, year] + for i in range(0, 3): + index = i-1 + if birthday[index] < 10: + birthday[index] = '0'+str(birthday[index]) + else: + birthday[index] = str(birthday[index]) + return '/'.join(birthday) + @abstractmethod def gen(self): pass \ No newline at end of file diff --git a/pyFBIG/rg_product.py b/pyFBIG/rg_product.py index ee4da44..f71663a 100644 --- a/pyFBIG/rg_product.py +++ b/pyFBIG/rg_product.py @@ -21,15 +21,18 @@ def gen(self): if self.is_complete == False: return rg else: - _name = name.gen_name(is_complete=True) + person = name.gen_name(is_complete=True) + _name= person['name'] + _gender = person['gender'] parents = self.parents_creator(_name= _name) if parents['father'].split(' ')[0] == _name.split(' ')[0]: _list = _name.split(' ') _name = _list[0] + ' Junior ' + ' '.join(_list[1:]) rg_doc: dict = { 'name':_name, + 'gender': _gender, 'birth': { - 'birthday': '10/12/1991', + 'day': self.rand_birthday(), 'cite':'Pocos de Caldas', 'state':'MG' }, diff --git a/tests/test_gen_rg.py b/tests/test_gen_rg.py index 76e01ac..b5357a7 100644 --- a/tests/test_gen_rg.py +++ b/tests/test_gen_rg.py @@ -16,6 +16,11 @@ def test_product(self): product.is_complete = True result = product.gen() assert type(result) == dict + birthday = result['birth']['day'] + assert type(birthday) == str + list_birthday = birthday.split('/') + assert len(list_birthday) == 3 + assert len(list_birthday[0]) == 2 and len(list_birthday[1]) == 2 and len(list_birthday[2]) == 4 if __name__ == "__main__": TestGenRG.test_factory() diff --git a/tests/test_name.py b/tests/test_name.py index 45e98b8..386aa4c 100644 --- a/tests/test_name.py +++ b/tests/test_name.py @@ -54,7 +54,7 @@ def test_gen_name(self): result = _name.gen_name(is_complete=False) assert type(result) == str result = _name.gen_name(is_complete=True) - assert len(result.split(' ')) == 3 + assert len(result['name'].split(' ')) == 3 def test_gen_male_name(self): _name = Name()