python foneygen:根据北美编号计划规则生成所有可能的可用美国电话号码列表。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python foneygen:根据北美编号计划规则生成所有可能的可用美国电话号码列表。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python

"""
FoneyGen: Generate a list of all potential usable US phone numbers
following North American Numbering Plan rules.

Author: Daniel Smith (https://github.com/ifnull/)

Usage:
    foneygen.py area-codes
    foneygen.py phone-numbers --npa <argument>

Options:
    -h --help     Show this screen.
    --version     Show version.
    --npa=<npa>   Specify area code.

"""

from docopt import docopt


def main():
    arguments = docopt(__doc__, version='FoneyGen 0.1')

    if arguments['area-codes'] is True:
        npas = generate_npas()

        for i in npas:
            print i

    if arguments['phone-numbers'] is True:
        npa = arguments['--npa']
        pns = generate_phone_numbers(npa)

        for i in pns:
            print i


def generate_npas():
    """
    NPA (Area Code) Rules:
    http://www.nanpa.com/area_codes/index.html
    * Starts with [2-9].
    * Does not end in 11 (N11).
    * Does not end in 9* (N9X).
    * Does not start with 37 (37X).
    * Does not start with 96 (96X).
    * Does not contain ERC (Easily Recognizable
      Codes) AKA last two digits aren't the same.
    """
    npa = []
    for x in range(200, 1000):
        s = str(x)

        # N11
        if s[1:] == '11':
            continue

        # N9X
        if s[1:-1] == '9':
            continue

        # 37X/96X
        if s[:2] == '37' or s[:2] == '96':
            continue

        # ERC
        if s[1:2] == s[2:3]:
            continue

        npa.append(x)

    return npa


def generate_cos():
    """
    CO (Prefix) Rules:
    * Starts with [2-9].
    * Does not end with 11 (N11).
    """
    co = []
    for x in range(200, 1000):
        s = str(x)

        # N11
        if s[1:] == '11':
            continue
        co.append(x)

    return co


def generate_phone_numbers(npa):

    pns = []

    for co in generate_cos():
        for sub in range(1, 10000):
            sub = "%04d" % sub
            pn = '{0}{1}{2}'.format(npa, co, sub)
            pns.append(pn)

    return pns


if __name__ == "__main__":
    main()

以上是关于python foneygen:根据北美编号计划规则生成所有可能的可用美国电话号码列表。的主要内容,如果未能解决你的问题,请参考以下文章

powershell脚本根据服务器编号执行操作

LeetCode 879. 盈利计划(动规典范题!)/ 牛客:找零 / 机器人跳跃问题

软件概要设计说明书—模板

python大佬养成计划----HTML网页设计(序列)

Covetrus向北美及全球业务引入新的职务和领导力

MySQL索引及执行计划