Giter Site home page Giter Site logo

ciscorn / phonenumbers-jp-py Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 198 KB

Parse Japanese phone numbers and extracts information such as their type and area. 日本の電話番号から、種別や市外局番などの情報を取得します。

License: MIT License

Python 100.00%
python phonenumber japan

phonenumbers-jp-py's Introduction

phonenumbers-jp-py

Test codecov pypi package

Parse Japanese phone numbers and extracts information such as their type and area.

日本国内の電話番号から、種別や市外局番などの情報を取得します。

License: MIT

Installation

pip3 install phonenumbers-jp -U

Examples

>>> phonenumbers_jp.parse("0311111111")
NumberInfo(parts=['03', '1111', '1111'], type='固定', subtype=None, message_area=NumberAndName(number='03', name='東京'), specified_carrier=None, callerid_delivery=None)

>>> phonenumbers_jp.parse("0992000000")
NumberInfo(parts=['099', '200', '0000'], type='固定', subtype=None, message_area=NumberAndName(number='099', name='鹿児島'), specified_carrier=None, callerid_delivery=None)

>>> phonenumbers_jp.parse("1840992000000")
NumberInfo(parts=['184', '099', '200', '0000'], type='固定', subtype=None, message_area=NumberAndName(number='099', name='鹿児島'), specified_carrier=None, callerid_delivery='withhold')

>>> phonenumbers_jp.parse("09011112222")
NumberInfo(parts=['090', '1111', '2222'], type='携帯', subtype=None, message_area=None, specified_carrier=None, callerid_delivery=None)

>>> phonenumbers_jp.parse("117")
NumberInfo(parts=['117'], type='特番', subtype='時報', message_area=None, specified_carrier=None, callerid_delivery=None)

>>> phonenumbers_jp.parse("05012345678")
NumberInfo(parts=['050', '1234', '5678'], type='IP', subtype=None, message_area=None, specified_carrier=None, callerid_delivery=None)

>>> phonenumbers_jp.parse("00630111111111")
NumberInfo(parts=['0063', '011', '111', '1111'], type='固定', subtype=None, message_area=NumberAndName(number='011', name='札幌'), specified_carrier=NumberAndName(number='0063', name='ソフトバンク株式会社'), callerid_delivery=None)

>>> phonenumbers_jp.parse("0120444444")
NumberInfo(parts=['0120', '444', '444'], type='フリーダイヤル', subtype=None, message_area=None, specified_carrier=None, callerid_delivery=None)

API

NumberType = Literal[
    "特番", "固定", "携帯", "IP", "M2M", "国際電話", "国外",
    "フリーダイヤル", "FMC", "ポケベル", "災害募金サービス", "ナビダイヤル", "テレドーム"
]

@dataclass
class NumberAndName:
    number: str
    name: str

@dataclass
class NumberInfo:
    parts: List[str] = field(default_factory=list)  # 分解された電話番号
    type: Optional[NumberType] = None  # 種別
    subtype: Optional[str] = None  # 特番の内容
    message_area: Optional[NumberAndName] = None  # メッセージエリア (市外局番)
    specified_carrier: Optional[NumberAndName] = None  # 事業者指定番号
    callerid_delivery: Optional[Literal["withhold", "provide"]] = None  # 非通知・通知

def parse(number: str) -> NumberInfo:
    ...

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.