Phone Number Home SQLite database Github Project address: github.com/lalala223/p…
The installation
pip install phone-db
Copy the code
Use:
Query the total number of mobile phone number segments in the database
>>> from phone_db import Session, Phone, Region
>>> session = Session()
>>> session.query(Phone).count()
415284
Copy the code
Query the total number of Beijing Unicom mobile phone segment
>>> city = session.query(Region).filter_by(zip_code='100000').first()
>>> if city:
... city.phones.filter_by(type=2).count()
...
6355
Copy the code
Query the owning location of a specified mobile phone number segment
>>> num = session.query(Phone).filter_by(number=1761166).first()
>>> if num:
... num.detail()
...
(1761166, 'unicom', {'province': 'Beijing'.'city': 'Beijing'.'zip_code': '100000'.'area_code': '010'})
Copy the code
Data table structure
Phones table
id INTEGER NOT NULL,
number INTEGER,
type INTEGER,
region_id INTEGER,
PRIMARY KEY (id),
FOREIGN KEY(region_id) REFERENCES regions (id)
Copy the code
Regions table
id INTEGER NOT NULL,
province VARCHAR,
city VARCHAR,
zip_code VARCHAR,
area_code VARCHAR,
PRIMARY KEY (id)
Copy the code
Phones table Type Field card type definition
* 1 Mobile * 2 Unicom * 3 Telecom * 4 Telecom virtual operator * 5 Unicom virtual operator * 6 Mobile virtual operatorCopy the code
Data visualization
Download the phone.db file and view it using SQliteBrowser
Record the number of
415284 (Updated :2 月 2019)