Ejemplo n.º 1
0
    def ssn(self, min_age=18, max_age=90, long=False, dash=True):
        """
        Returns a 10 or 12 (long=True) digit Swedish SSN, "Personnummer".

        It consists of 10 digits in the form (CC)YYMMDD-SSSQ, where
        YYMMDD is the date of birth, SSS is a serial number
        and Q is a control character (Luhn checksum).

        Specifying dash=False will give a purely numeric string, suitable
        for writing direct to databases.

        http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
        """

        age = datetime.timedelta(
            days=self.generator.random.randrange(min_age * 365, max_age * 365))
        birthday = datetime.datetime.now() - age
        yr_fmt = '%Y' if long else '%y'
        pnr_date = birthday.strftime('{}%m%d'.format(yr_fmt))
        chk_date = pnr_date[2:] if long else pnr_date
        suffix = str(self.generator.random.randrange(0, 999)).zfill(3)
        luhn_checksum = str(calculate_luhn(chk_date + suffix))
        hyphen = '-' if dash else ''
        pnr = '{}{}{}{}'.format(pnr_date, hyphen, suffix, luhn_checksum)

        return pnr
Ejemplo n.º 2
0
 def test_luhn_checksum(self):
     """
     Tests if a valid checksum is generated
     Example from wiki: https://en.wikipedia.org/wiki/Luhn_algorithm
     """
     check_digit = calculate_luhn("7992739871")
     assert check_digit == 3
Ejemplo n.º 3
0
    def ssn(
        self,
        min_age: int = 18,
        max_age: int = 90,
        long: bool = False,
        dash: bool = True,
    ) -> str:
        """
        Returns a 10 or 12 (long=True) digit Swedish SSN, "Personnummer".

        It consists of 10 digits in the form (CC)YYMMDD-SSSQ, where
        YYMMDD is the date of birth, SSS is a serial number
        and Q is a control character (Luhn checksum).

        Specifying dash=False will give a purely numeric string, suitable
        for writing direct to databases.

        http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
        """

        age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))
        birthday = datetime.datetime.now() - age
        yr_fmt = "%Y" if long else "%y"
        pnr_date = f"{birthday:{yr_fmt}%m%d}"
        chk_date = pnr_date[2:] if long else pnr_date
        suffix = f"{self.generator.random.randrange(0, 999):03}"
        luhn_checksum = str(calculate_luhn(int(chk_date + suffix)))
        hyphen = "-" if dash else ""
        pnr = f"{pnr_date}{hyphen}{suffix}{luhn_checksum}"

        return pnr
Ejemplo n.º 4
0
 def company_vat(self):
     """
     Returns Italian VAT identification number (Partita IVA).
     """
     code = "0" + self.bothify('######') + str(self.generator.random.randrange(1, 121)).zfill(3)
     luhn_checksum = str(calculate_luhn(code))
     return 'IT{}{}'.format(code, luhn_checksum)
Ejemplo n.º 5
0
 def company_vat(self):
     """
     Returns Italian VAT identification number (Partita IVA).
     """
     code = self.bothify('#######') + str(self._random_vat_office()).zfill(3)
     luhn_checksum = str(calculate_luhn(code))
     return f'IT{code}{luhn_checksum}'
Ejemplo n.º 6
0
    def aadhaar_id(self):
        """
        Aadhaar is a 12 digit person identifier generated for residents of
        India.
        Details: https://en.wikipedia.org/wiki/Aadhaar
        Official Website: https://uidai.gov.in/my-aadhaar/about-your-aadhaar.html
        """

        aadhaar_digits = self.numerify(self.random_element(self.aadhaar_id_formats))
        checksum = checksums.calculate_luhn(aadhaar_digits)

        aadhaar_number = '{}{}'.format(aadhaar_digits, checksum)

        return aadhaar_number
Ejemplo n.º 7
0
    def org_id(self, long=False, dash=True):
        """
        Returns a 10 or 12 digit Organisation ID for a Swedish
        company.
        (In Swedish) https://sv.wikipedia.org/wiki/Organisationsnummer
        """
        first_digits = list(self.ORG_ID_DIGIT_1)
        random.shuffle(first_digits)
        onr_one = str(first_digits.pop())
        onr_one += str(self.generator.random.randrange(0, 9)).zfill(1)
        onr_one += str(self.generator.random.randrange(20, 99))
        onr_one += str(self.generator.random.randrange(0, 99)).zfill(2)
        onr_two = str(self.generator.random.randrange(0, 999)).zfill(3)
        luhn_checksum = str(calculate_luhn(onr_one + onr_two))
        prefix = '16' if long else ''
        hyphen = '-' if dash else ''

        org_id = f'{prefix}{onr_one}{hyphen}{onr_two}{luhn_checksum}'
        return org_id