Source code for mimesis.builtins.en

# -*- coding: utf-8 -*-

"""Specific data provider for USA (en)."""

from typing import Optional

from mimesis.builtins.base import BaseSpecProvider
from mimesis.locales import Locale
from mimesis.typing import Seed

__all__ = ["USASpecProvider"]


[docs]class USASpecProvider(BaseSpecProvider): """Class that provides special data for USA (en)."""
[docs] def __init__(self, seed: Optional[Seed] = None) -> None: """Initialize attributes.""" super().__init__(locale=Locale.EN, seed=seed)
[docs] class Meta: """The name of the provider.""" name = "usa_provider"
[docs] def tracking_number(self, service: str = "usps") -> str: """Generate random tracking number. Supported services: USPS, FedEx and UPS. :param str service: Post service. :return: Tracking number. """ service = service.lower() if service not in ("usps", "fedex", "ups"): raise ValueError("Unsupported post service") services = { "usps": ( "#### #### #### #### ####", "@@ ### ### ### US", ), "fedex": ( "#### #### ####", "#### #### #### ###", ), "ups": ("1Z@####@##########",), } mask = self.random.choice(services[service]) return self.random.custom_code(mask=mask)
[docs] def ssn(self) -> str: """Generate a random, but valid SSN. :returns: SSN. :Example: 569-66-5801 """ area = self.random.randint(1, 899) if area == 666: area = 665 return "{:03}-{:02}-{:04}".format( area, self.random.randint(1, 99), self.random.randint(1, 9999), )