__init__.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import itertools
  2. from datetime import date
  3. from decimal import Decimal
  4. from typing import Dict, List, Optional, Tuple, Union
  5. from ...typing import GenderType
  6. from .. import BaseProvider
  7. class Provider(BaseProvider):
  8. """
  9. This provider is a collection of functions to generate personal profiles and identities.
  10. """
  11. def simple_profile(self, sex: Optional[GenderType] = None) -> Dict[str, Union[str, date, GenderType]]:
  12. """
  13. Generates a basic profile with personal informations
  14. """
  15. sex_ = self.random_element(["F", "M"]) if sex is None else sex
  16. if sex_ == "F":
  17. name = self.generator.name_female()
  18. elif sex_ == "M":
  19. name = self.generator.name_male()
  20. return {
  21. "username": self.generator.user_name(),
  22. "name": name,
  23. "sex": sex_,
  24. "address": self.generator.address(),
  25. "mail": self.generator.free_email(),
  26. "birthdate": self.generator.date_of_birth(),
  27. }
  28. def profile(
  29. self, fields: Optional[List[str]] = None, sex: Optional[GenderType] = None
  30. ) -> Dict[str, Union[str, Tuple[Decimal, Decimal], List[str], date]]:
  31. """
  32. Generates a complete profile.
  33. If "fields" is not empty, only the fields in the list will be returned
  34. """
  35. if fields is None:
  36. fields = []
  37. d = {
  38. "job": self.generator.job(),
  39. "company": self.generator.company(),
  40. "ssn": self.generator.ssn(),
  41. "residence": self.generator.address(),
  42. "current_location": (self.generator.latitude(), self.generator.longitude()),
  43. "blood_group": "".join(self.random_element(list(itertools.product(["A", "B", "AB", "O"], ["+", "-"])))),
  44. "website": [self.generator.url() for _ in range(1, self.random_int(2, 5))],
  45. }
  46. d = dict(d, **self.generator.simple_profile(sex))
  47. # field selection
  48. if len(fields) > 0:
  49. d = {k: v for k, v in d.items() if k in fields}
  50. return d