1010import uuid
1111import random
1212from typing import List , Tuple
13+ from dataclasses import dataclass , asdict
1314
15+ # Ensure the current directory is in the path to import local modules
1416# Adjust your path as needed
1517sys .path .append ('.' )
1618
19+ from random_profile .enums import gender
1720from random_profile .enums .gender import Gender
1821from random_profile import utils
1922from random_profile .__about__ import __version__
4245job_titles = utils .load_txt_file (job_titles_txt )
4346job_levels = utils .load_txt_file (job_levels_txt )
4447
48+ @dataclass
49+ class Profile :
50+ id : str
51+ gender : str
52+ first_name : str
53+ last_name : str
54+ full_name : str
55+ hair_color : str
56+ blood_type : str
57+ job_title : str
58+ dob : str
59+ age : int
60+ phone_number : str
61+ email : str
62+ height : int
63+ weight : int
64+ ip_address : str
65+ address : dict
66+ full_address : str
67+ job_experience : str
68+ mother : str
69+ father : str
70+ payment_card : dict
71+ coordinates : str
4572
4673class RandomProfile :
4774 """
@@ -95,6 +122,9 @@ def __getitem__(self, index):
95122 profiles = self .full_profiles ()
96123 return profiles [index ]
97124
125+ def _resolve_count (self , num ):
126+ return self .num if num is None else num
127+
98128 def ip_address (self , num : int = None ) -> List [str ]:
99129 """Generate one or more IPv4 addresses."""
100130 count = self .num if num is None else num
@@ -107,21 +137,21 @@ def job_title(self, num: int = None) -> List[str]:
107137 count = self .num if num is None else num
108138 if count == 1 :
109139 return [random .choice (job_titles )]
110- return random .choices (job_titles , k = count )
140+ return random .choices (job_titles , k = self . _resolve_count ( num ) )
111141
112142 def blood_type (self , num : int = None ) -> List [str ]:
113143 """Generate one or more blood types."""
114144 count = self .num if num is None else num
115145 if count == 1 :
116146 return [random .choice (blood_types )]
117- return random .choices (blood_types , k = count )
147+ return random .choices (blood_types , k = self . _resolve_count ( num ) )
118148
119149 def hair_color (self , num : int = None ) -> List [str ]:
120150 """Generate one or more hair colors."""
121151 count = self .num if num is None else num
122152 if count == 1 :
123153 return [random .choice (hair_colors )]
124- return random .choices (hair_colors , k = count )
154+ return random .choices (hair_colors , k = self . _resolve_count ( num ) )
125155
126156 def dob_age (self , num : int = None ) -> List [Tuple [str , int ]]:
127157 """Generate DOB and age tuples."""
@@ -175,14 +205,14 @@ def first_names(self, num: int = None, gender: Gender = None) -> List[str]:
175205
176206 if count == 1 :
177207 return [random .choice (names_pool )]
178- return random .choices (names_pool , k = count )
208+ return random .choices (names_pool , k = self . _resolve_count ( num ) )
179209
180210 def last_names (self , num : int = None ) -> List [str ]:
181211 """Generate one or more last names."""
182212 count = self .num if num is None else num
183213 if count == 1 :
184214 return [random .choice (lname )]
185- return random .choices (lname , k = count )
215+ return random .choices (lname , k = self . _resolve_count ( num ) )
186216
187217 def full_names (self , num : int = None , gender : Gender = None ) -> List [str ]:
188218 """Generate one or more full names (first + last)."""
@@ -251,31 +281,56 @@ def full_profiles(self, num: int = None, gender: Gender = None) -> List[dict]:
251281 card = utils .generate_random_card ()
252282
253283 # Compose the profile dict
254- profile = {
255- 'id' : str (uuid .uuid4 ()),
256- 'gender' : this_gender .value ,
257- 'first_name' : f_name ,
258- 'last_name' : l_name ,
259- 'full_name' : full_name ,
260- 'hair_color' : [hair ], # matching the list return type from hair_color()
261- 'blood_type' : [blood ], # matching the list return type from blood_type()
262- 'job_title' : [random .choice (job_titles )],
263- 'dob' : dob ,
264- 'age' : age ,
265- 'phone_number' : phone_number ,
266- 'email' : f"{ f_name .lower ()} { l_name .lower ()} @example.com" ,
267- 'height' : height ,
268- 'weight' : weight ,
269- 'ip_address' : [utils .ipv4_gen ()], # typically returns a list
270- 'address' : address_dict ,
271- 'full_address' : full_address ,
272- 'job_experience' : job_experience ,
273- 'mother' : mother ,
274- 'father' : father ,
275- 'payment_card' : card ,
276- 'coordinates' : coords_pretty
277- }
278-
279- profile_list .append (profile )
284+ # profile = {
285+ # 'id': str(uuid.uuid4()),
286+ # 'gender': this_gender.value,
287+ # 'first_name': f_name,
288+ # 'last_name': l_name,
289+ # 'full_name': full_name,
290+ # 'hair_color': hair, # matching the list return type from hair_color()
291+ # 'blood_type': blood, # matching the list return type from blood_type()
292+ # 'job_title': random.choice(job_titles),
293+ # 'dob': dob,
294+ # 'age': age,
295+ # 'phone_number': phone_number,
296+ # 'email': f"{f_name.lower()}{l_name.lower()}@example.com",
297+ # 'height': height,
298+ # 'weight': weight,
299+ # 'ip_address': utils.ipv4_gen(), # typically returns a list
300+ # 'address': address_dict,
301+ # 'full_address': full_address,
302+ # 'job_experience': job_experience,
303+ # 'mother': mother,
304+ # 'father': father,
305+ # 'payment_card': card,
306+ # 'coordinates': coords_pretty
307+ # }
308+
309+ # profile_list.append(profile)
310+ profile = Profile (
311+ id = str (uuid .uuid4 ()),
312+ gender = this_gender .value if this_gender .value is not None else "" ,
313+ first_name = f_name ,
314+ last_name = l_name ,
315+ full_name = full_name ,
316+ hair_color = hair ,
317+ blood_type = blood ,
318+ job_title = random .choice (job_titles ),
319+ dob = dob ,
320+ age = age ,
321+ phone_number = phone_number ,
322+ email = f"{ f_name .lower ()} { l_name .lower ()} @example.com" ,
323+ height = height ,
324+ weight = weight ,
325+ ip_address = utils .ipv4_gen (),
326+ address = address_dict ,
327+ full_address = full_address ,
328+ job_experience = job_experience ,
329+ mother = mother ,
330+ father = father ,
331+ payment_card = card ,
332+ coordinates = coords_pretty
333+ )
334+ profile_list .append (asdict (profile ))
280335
281336 return profile_list
0 commit comments