Compare commits

...

3 Commits
v1.0.1 ... main

Author SHA1 Message Date
61ea239cb0
whitespace fuckshit 2024-12-23 19:44:19 -05:00
347f869d2d
center logo 2024-12-23 19:40:26 -05:00
72b2cb7591
Added logo 2024-12-23 19:39:00 -05:00
3 changed files with 150 additions and 143 deletions

BIN
.screens/nanpa.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -1,4 +1,9 @@
# NANPA API Client # NANPA API Client
<p align="center">
<img src="./.screens/nanpa.png">
</p>
A Python client for interacting with the North American Numbering Plan Administration (NANPA) public API system. A Python client for interacting with the North American Numbering Plan Administration (NANPA) public API system.
## Overview ## Overview

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# North American Numbering Plan Administration (NANPA) API Client - Developed by acidvegas in Python (https://git.acid.vegas/nanpa) # North American Numbering Plan Administration (NANPA) API Client - Developed by acidvegas in Python (https://git.acid.vegas/nanpa)
# nanpa/client.py
import json import json
import logging import logging
@ -9,210 +10,211 @@ import urllib.request
class NanpaAPI: class NanpaAPI:
def __init__(self): def __init__(self):
'''Initialize the NANPA API client.''' '''Initialize the NANPA API client.'''
self.base_url = 'https://api.nanpa.com/reports/public' self.base_url = 'https://api.nanpa.com/reports/public'
def _make_request(self, endpoint: str, params: dict = None) -> dict:
'''
Make a request to the NANPA API.
:param endpoint: API endpoint to call
:param params: Optional query parameters
'''
url = f'{self.base_url}/{endpoint}'
if params:
url += '?' + urllib.parse.urlencode(params)
try:
with urllib.request.urlopen(url) as response:
return json.loads(response.read().decode())
except urllib.error.URLError as e:
logging.error(f'Failed to make request to {url}: {e}')
return None
def get_9yy_codes(self) -> dict: def _make_request(self, endpoint: str, params: dict = None) -> dict:
'''Get 9YY specialty codes.''' '''
Make a request to the NANPA API.
return self._make_request('specialityResources/9yy/codes') :param endpoint: API endpoint to call
:param params: Optional query parameters
'''
url = f'{self.base_url}/{endpoint}'
if params:
url += '?' + urllib.parse.urlencode(params)
try:
with urllib.request.urlopen(url) as response:
return json.loads(response.read().decode())
except urllib.error.URLError as e:
logging.error(f'Failed to make request to {url}: {e}')
return None
def get_area_code_info(self, npa: str) -> dict: def get_9yy_codes(self) -> dict:
''' '''Get 9YY specialty codes.'''
Get detailed information about a specific area code.
:param npa: Area code to lookup
'''
params = {'npa': npa} return self._make_request('specialityResources/9yy/codes')
return self._make_request('npa/areaCodeListing', params)
def get_area_codes_by_state(self, state: str) -> dict: def get_area_code_info(self, npa: str) -> dict:
''' '''
Get area codes for a specific state. Get detailed information about a specific area code.
:param state: Two-letter state code
'''
params = {'states': state, 'isExternal': 'false'} :param npa: Area code to lookup
'''
return self._make_request('code/getNpasForStates', params) params = {'npa': npa}
return self._make_request('npa/areaCodeListing', params)
def get_co_code_forecast(self, state: str, npa: str) -> dict: def get_area_codes_by_state(self, state: str) -> dict:
''' '''
Get CO code forecast information. Get area codes for a specific state.
:param state: Two-letter state code
:param npa: Area code
''' :param state: Two-letter state code
'''
params = {'state': state, 'npa': npa} params = {'states': state, 'isExternal': 'false'}
return self._make_request('tbco/coCodeForecast', params) return self._make_request('code/getNpasForStates', params)
def get_current_pool_tracking(self, state: str, npa: str) -> dict: def get_co_code_forecast(self, state: str, npa: str) -> dict:
''' '''
Get current pool tracking information. Get CO code forecast information.
:param state: Two-letter state code
:param npa: Area code
'''
params = {'state': state, 'npa': npa} :param state: Two-letter state code
:param npa: Area code
return self._make_request('tbco/currentPoolTracking', params) '''
params = {'state': state, 'npa': npa}
return self._make_request('tbco/coCodeForecast', params)
def get_lrn_forecast(self, state: str, npa: str) -> dict: def get_current_pool_tracking(self, state: str, npa: str) -> dict:
''' '''
Get LRN forecast information. Get current pool tracking information.
:param state: Two-letter state code
:param npa: Area code
'''
params = {'state': state, 'npa': npa} :param state: Two-letter state code
:param npa: Area code
'''
return self._make_request('tbco/lrnForecast', params) params = {'state': state, 'npa': npa}
return self._make_request('tbco/currentPoolTracking', params)
def get_pooling_forecast(self, state: str, npa: str) -> dict: def get_lrn_forecast(self, state: str, npa: str) -> dict:
''' '''
Get pooling forecast information. Get LRN forecast information.
:param state: Two-letter state code
:param npa: Area code
'''
params = {'state': state, 'npa': npa} :param state: Two-letter state code
:param npa: Area code
'''
return self._make_request('tbco/poolingForecast', params) params = {'state': state, 'npa': npa}
return self._make_request('tbco/lrnForecast', params)
def get_pstn_activation(self, state: str) -> dict: def get_pooling_forecast(self, state: str, npa: str) -> dict:
''' '''
Get PSTN activation information. Get pooling forecast information.
:param state: Two-letter state code
'''
params = {'state': state} :param state: Two-letter state code
:param npa: Area code
'''
return self._make_request('tbco/pstnActivation', params) params = {'state': state, 'npa': npa}
return self._make_request('tbco/poolingForecast', params)
def get_rate_center_changes(self, start_date: str, end_date: str) -> dict: def get_pstn_activation(self, state: str) -> dict:
''' '''
Get rate center changes between two dates. Get PSTN activation information.
:param start_date: Start date in format YYYY-MM-DDT00:00:00.000-05:00
:param end_date: End date in format YYYY-MM-DDT23:59:59.999-05:00
'''
params = {'startDate': start_date, 'endDate': end_date} :param state: Two-letter state code
'''
return self._make_request('npa/rateCenterChanges', params) params = {'state': state}
return self._make_request('tbco/pstnActivation', params)
def get_rate_centers(self, state: str) -> dict: def get_rate_center_changes(self, start_date: str, end_date: str) -> dict:
''' '''
Get rate centers for a specific state. Get rate center changes between two dates.
:param state: Two-letter state code
'''
params = {'state': state} :param start_date: Start date in format YYYY-MM-DDT00:00:00.000-05:00
:param end_date: End date in format YYYY-MM-DDT23:59:59.999-05:00
'''
return self._make_request('npa/rateCenters', params) params = {'startDate': start_date, 'endDate': end_date}
return self._make_request('npa/rateCenterChanges', params)
def get_specialty_codes_aging(self) -> dict: def get_rate_centers(self, state: str) -> dict:
'''Get aging 5XX specialty codes.''' '''
Get rate centers for a specific state.
return self._make_request('specialityResources/5xx/aging') :param state: Two-letter state code
'''
params = {'state': state}
return self._make_request('npa/rateCenters', params)
def get_specialty_codes_assigned(self) -> dict: def get_specialty_codes_aging(self) -> dict:
'''Get assigned 5XX specialty codes.''' '''Get aging 5XX specialty codes.'''
return self._make_request('specialityResources/5xx/assigned') return self._make_request('specialityResources/5xx/aging')
def get_specialty_codes_available(self, code_type: str = '5xx') -> dict: def get_specialty_codes_assigned(self) -> dict:
''' '''Get assigned 5XX specialty codes.'''
Get available specialty codes.
:param code_type: Code type ('5xx' or '9yy')
'''
return self._make_request(f'specialityResources/{code_type}/available') return self._make_request('specialityResources/5xx/assigned')
def get_states(self) -> dict: def get_specialty_codes_available(self, code_type: str = '5xx') -> dict:
'''Get all NANPA states and territories.''' '''
Get available specialty codes.
return self._make_request('nanpaStates') :param code_type: Code type ('5xx' or '9yy')
'''
return self._make_request(f'specialityResources/{code_type}/available')
def get_thousands_blocks(self, state: str, npa: str, report_type: str = 'AS') -> dict: def get_states(self) -> dict:
''' '''Get all NANPA states and territories.'''
Get thousands blocks information.
:param state: Two-letter state code
:param npa: Area code
:param report_type: Report type (default: AS)
'''
params = {'state': state, 'npa': npa, 'reportType': report_type} return self._make_request('nanpaStates')
return self._make_request('tbco/thousandsBlocks', params)
def get_thousands_blocks(self, state: str, npa: str, report_type: str = 'AS') -> dict:
'''
Get thousands blocks information.
:param state: Two-letter state code
:param npa: Area code
:param report_type: Report type (default: AS)
'''
params = {'state': state, 'npa': npa, 'reportType': report_type}
return self._make_request('tbco/thousandsBlocks', params)
def main(): def main():
'''Example usage of the NANPA API client.''' '''Example usage of the NANPA API client.'''
client = NanpaAPI() client = NanpaAPI()
# Example API calls # Example API calls
states = client.get_states() states = client.get_states()
logging.info(f'States: {json.dumps(states, indent=2)}') logging.info(f'States: {json.dumps(states, indent=2)}')
fl_codes = client.get_area_codes_by_state('FL') fl_codes = client.get_area_codes_by_state('FL')
logging.info(f'Florida area codes: {json.dumps(fl_codes, indent=2)}') logging.info(f'Florida area codes: {json.dumps(fl_codes, indent=2)}')
area_info = client.get_area_code_info('301') area_info = client.get_area_code_info('301')
logging.info(f'301 area code info: {json.dumps(area_info, indent=2)}') logging.info(f'301 area code info: {json.dumps(area_info, indent=2)}')
if __name__ == '__main__': if __name__ == '__main__':
main() main()