Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fake USPTO Patent Numbers #1184

Closed
ex-nerd opened this issue May 19, 2020 · 4 comments
Closed

Fake USPTO Patent Numbers #1184

ex-nerd opened this issue May 19, 2020 · 4 comments
Labels

Comments

@ex-nerd
Copy link

ex-nerd commented May 19, 2020

Feels like too much work right now to disable black and automatic formatting stuff I use, and downgrade this to work with python2, and not sure if it's something worthy of fitting into the core of faker. So for now, if you would like a provider that generates proper USPTO patent numbers, here is some code to start with. If this is worthy of a PR, just let me know and I'll submit it as such.

from faker.providers import BaseProvider


class USPTOProvider(BaseProvider):
    """
    Generates random patent numbers based on the rules from the USPTO:
    https://www.uspto.gov/patents-application-process/applying-online/patent-number

    """

    def uspto_num(self) -> str:
        """ Returns a patent number of a random type """
        fn = self.generator.random_element(
            elements=(
                self.uspto_utility,
                self.uspto_reissue,
                self.uspto_plant,
                self.uspto_design,
                self.uspto_ai,
                self.uspto_x,
                self.uspto_h,
                self.uspto_t,
            )
        )
        return fn()

    def uspto_utility(self) -> str:
        # Utility : Patent numbers consist of six, seven or eight digits. Enter the
        # Patent number excluding commas and spaces and omit leading zeroes.
        num_digits = self.generator.random_int(6, 8)
        return str(self.generator.random_number(digits=num_digits, fix_len=True))

    def uspto_reissue(self) -> str:
        # Reissue : (e.g., Rennnnnn, RE000126) must enter leading zeroes between "RE"
        # and number to create 6 digits.
        return f"RE{self.generator.random_number(digits=6):06}"

    def uspto_plant(self) -> str:
        # Plant Patents :(e.g., PPnnnnnn, PP000126) must enter leading zeroes between
        # "PP" and number to create 6 digits.
        return f"PP{self.generator.random_number(digits=6):06}"

    def uspto_design(self) -> str:
        # Design : (e.g., Dnnnnnnn, D0000126) must enter leading zeroes between "D" and
        # number to create 7 digits.
        return f"D{self.generator.random_number(digits=7):07}"

    def uspto_ai(self) -> str:
        # Additions of Improvements : (e.g., AInnnnnn , AI000126) must enter leading
        # zeroes between "AI" and number tocreate 6 digits.
        return f"AI{self.generator.random_number(digits=6):06}"

    def uspto_x(self) -> str:
        # X Patents : (e.g., Xnnnnnnn , X0000001) must enter leading zeroes between "X"
        # and number to create 7 digits.
        return f"X{self.generator.random_number(digits=7):07}"

    def uspto_h(self) -> str:
        # H Documents : (e.g., Hnnnnnnn , H0000001) must enter leading zeroes between
        # "H" and number to create 7 digits.
        return f"H{self.generator.random_number(digits=7):07}"

    def uspto_t(self) -> str:
        # T Documents : (e.g., Tnnnnnnn , T0000001) must enter leading zeroes between
        # "T" and number to create 7 digits.
        return f"T{self.generator.random_number(digits=7):07}"
@malefice
Copy link
Contributor

Faker has already dropped Python 2 support, so feel free to only use Python 3, but Python 3.5 is still being supported, so that means no f-strings, unfortunately. As for whether or not this can be included in Faker or is better implemented as a separate package, I will defer to @fcurella.

If this is to be a separate package, then at least you do not have to retool or change your settings, and it will be up to you which Python versions you want to support as long as Faker itself also supports those versions.

@fcurella
Copy link
Collaborator

Hi @ex-nerd !

I think this provider is too narrow to be included in Faker itself. Feel free to package it as an external provider, and I'll be happy to include it in our Community Providers page!

@github-actions
Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Mar 12, 2022
@github-actions
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants