手機號碼歸屬地SQLite數據庫
Github項目地址:https://github.com/lalala223/phone-db
安裝
pip install phone-db
使用:
查詢數據庫中手機號段總條數
>>> from phone_db import Session, Phone, Region
>>> session = Session()
>>> session.query(Phone).count()
415284
查詢北京市聯通手機號段總條數
>>> city = session.query(Region).filter_by(zip_code='100000').first()
>>> if city:
... city.phones.filter_by(type=2).count()
...
6355
查詢指定手機號段歸屬地信息
>>> num = session.query(Phone).filter_by(number=1761166).first()
>>> if num:
... num.detail()
...
(1761166, '聯通', {'province': '北京', 'city': '北京', 'zip_code': '100000', 'area_code': '010'})
數據表結構
phones表
id INTEGER NOT NULL,
number INTEGER,
type INTEGER,
region_id INTEGER,
PRIMARY KEY (id),
FOREIGN KEY(region_id) REFERENCES regions (id)
regions表
id INTEGER NOT NULL,
province VARCHAR,
city VARCHAR,
zip_code VARCHAR,
area_code VARCHAR,
PRIMARY KEY (id)
phones表type字段卡類型定義
* 1 移動
* 2 聯通
* 3 電信
* 4 電信虛擬運營商
* 5 聯通虛擬運營商
* 6 移動虛擬運營商
數據可視化
下載phone.db文件,使用sqlitebrowser查看
記錄條數
415284 (updated:2019年2月)