Giter Site home page Giter Site logo

phone-gen's Introduction

Phone Gen

PyPI Downloads PyPI - Python Version PyPI - Implementation

Code style: black Code style: black

International phone number generation

This module was created exclusively for generating test data

Installation

Install using pip with

pip install phone-gen

Example

from phone_gen import PhoneNumber

phone_number = PhoneNumber("GB")  # ISO 3166-2
# or
phone_number = PhoneNumber("GBR")  # ISO 3166-3
# or
phone_number = PhoneNumber("Great Britain")  # Country name

# Get a phone number
number = phone_number.get_number()
print(number)  # +442908124840

# Get a country code
country_code = phone_number.get_code()
print(country_code)  # 44

# Get a phone number without a country code
number = phone_number.get_number(full=False)
print(number)  # 183782623

# Get a mobile phone number
number = phone_number.get_mobile()
print(number)  # +447911899521

# Get a national phone number
number = phone_number.get_national()
print(number)  # +442408055065
pytest fixture
import pytest
from phone_gen import PhoneNumber


@pytest.fixture
def phone_number():
    def wrap(code):
        return PhoneNumber(code).get_number()

    yield wrap


def test_one(phone_number):
    number = phone_number("DE")
    ...

Using the CLI

usage: phone-gen [-h] [-v] [-n] country [country ...]

International phone number generation

positional arguments:
  country         Country code or country name. Example: "GB" or "GBR" or "Great Britain"

optional arguments:
  -h, --help      show this help message and exit
  -v, --version   show program's version number and exit
  -f, --not-full  Get a phone number without a country code
  -m, --mobile    Get mobile phone number
  -n, --national  Get national phone number

Example

# Get a phone number

$ phone-gen DE
+49791774007056

$ phone-gen DEU
+499968635

$ phone-gen Germany
+49960335800


# Get a phone number without a country code
$ phone-gen -f DE
66999511

$ phone-gen -f Germany
877595

# Get mobile phone number
$ phone-gen -m DE
+491601376066

# Get national phone number
$ phone-gen -n DE
+4940381

Resources

Changelog

Contributing

Contributions are very welcome.

You might want to:

  • Fix spelling errors
  • Improve documentation
  • Add tests for untested code
  • Add new features
  • Fix bugs

Getting started

  • python 3.11
  • pipenv 2022.12.19+
  1. Clone the repository
    git clone https://github.com/tolstislon/phone-gen.git
    cd phone-gen
  2. Install dev dependencies
    pipenv install --dev
    pipenv shell
  3. Run the linters
    black phone_gen/ 
    flake8 phone_gen/
  4. Run the tests
    pytest tests/

phone-gen's People

Contributors

tolstislon avatar vishalksimplify avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phone-gen's Issues

Help me

How to read message received for that numbers

Failed tests

PHONENUMBERS="8.12.9"
platform linux -- Python 3.6.10, pytest-6.1.1, py-1.9.0, pluggy-0.13.1

country = 'AT', count = 12
    @pytest.mark.phonenumbers
    @pytest.mark.parametrize('count', range(15))
    @pytest.mark.parametrize('country', PATTERNS['data'].keys())
    def test_patterns(country, count):
        phone_number = PhoneNumber(country)
        number = phone_number.get_number()
        num_obj = phonenumbers.parse(number, country)
>       assert phonenumbers.is_valid_number_for_region(num_obj, country)
E       AssertionError: assert False
E        +  where False = <function is_valid_number_for_region at 0x7fec6cb3bd40>(PhoneNumber(country_code=43, national_number=43516219, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None), 'AT')
E        +    where <function is_valid_number_for_region at 0x7fec6cb3bd40> = phonenumbers.is_valid_number_for_region
count      = 12
country    = 'AT'
num_obj    = PhoneNumber(country_code=43, national_number=43516219, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
number     = '+4343516219'
phone_number = <phone_gen._generator.PhoneNumber object at 0x7fec6b929890>
tests/test_phone.py:18: AssertionError

PHONENUMBERS="8.12.11"
platform linux -- Python 3.6.10, pytest-6.1.1, py-1.9.0, pluggy-0.13.1

country = 'AT', count = 10
    @pytest.mark.phonenumbers
    @pytest.mark.parametrize('count', range(15))
    @pytest.mark.parametrize('country', PATTERNS['data'].keys())
    def test_patterns(country, count):
        phone_number = PhoneNumber(country)
        number = phone_number.get_number()
        num_obj = phonenumbers.parse(number, country)
>       assert phonenumbers.is_valid_number_for_region(num_obj, country)
E       AssertionError: assert False
E        +  where False = <function is_valid_number_for_region at 0x7f0925b52510>(PhoneNumber(country_code=43, national_number=4351180365, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None), 'AT')
E        +    where <function is_valid_number_for_region at 0x7f0925b52510> = phonenumbers.is_valid_number_for_region
count      = 10
country    = 'AT'
num_obj    = PhoneNumber(country_code=43, national_number=4351180365, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
number     = '+434351180365'
phone_number = <phone_gen._generator.PhoneNumber object at 0x7f0924a5d7b8>
tests/test_phone.py:18: AssertionError

Search : Find all Country Code present in phone-gen

Good Work Team-Phone-Gen

Is there any way to find out the entire country-code which can be passed in this library ?

Ex :

from phone_gen import PhoneNumber
phone_number = PhoneNumber("GB") 

GB, USA, and how many more ?

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.