fcc-form499-api

- Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.acid.vegas/-c.git
Log | Files | Refs | Archive | README | LICENSE

fcc_form499.py (6037B)

      1 #!/usr/bin/env python3
      2 # FCC Form499 API Client - Developed by acidvegas in Python (https://git.acid.vegas/fcc-form499-api)
      3 
      4 from enum import Enum
      5 import urllib.error
      6 import urllib.parse
      7 import urllib.request
      8 
      9 class States(str, Enum):
     10     '''List of valid states'''
     11 
     12     ALABAMA                  = 'alabama'
     13     ALASKA                   = 'alaska'
     14     AMERICAN_SAMOA           = 'american_samoa'
     15     ARIZONA                  = 'arizona'
     16     ARKANSAS                 = 'arkansas'
     17     CALIFORNIA               = 'california'
     18     COLORADO                 = 'colorado'
     19     CONNECTICUT              = 'connecticut'
     20     DELAWARE                 = 'delaware'
     21     DISTRICT_OF_COLUMBIA     = 'district_of_columbia'
     22     FLORIDA                  = 'florida'
     23     GEORGIA                  = 'georgia'
     24     GUAM                     = 'guam'
     25     HAWAII                   = 'hawaii'
     26     IDAHO                    = 'idaho'
     27     ILLINOIS                 = 'illinois'
     28     INDIANA                  = 'indiana'
     29     IOWA                     = 'iowa'
     30     JOHNSTON_ATOLL           = 'johnston_atoll'
     31     KANSAS                   = 'kansas'
     32     KENTUCKY                 = 'kentucky'
     33     LOUISIANA                = 'louisiana'
     34     MAINE                    = 'maine'
     35     MARYLAND                 = 'maryland'
     36     MASSACHUSETTS            = 'massachusetts'
     37     MICHIGAN                 = 'michigan'
     38     MIDWAY_ATOLL             = 'midway_atoll'
     39     MINNESOTA                = 'minnesota'
     40     MISSISSIPPI              = 'mississippi'
     41     MISSOURI                 = 'missouri'
     42     MONTANA                  = 'montana'
     43     NEBRASKA                 = 'nebraska'
     44     NEVADA                   = 'nevada'
     45     NEW_HAMPSHIRE            = 'new_hampshire'
     46     NEW_JERSEY               = 'new_jersey'
     47     NEW_MEXICO               = 'new_mexico'
     48     NEW_YORK                 = 'new_york'
     49     NORTH_CAROLINA           = 'north_carolina'
     50     NORTH_DAKOTA             = 'north_dakota'
     51     NORTHERN_MARIANA_ISLANDS = 'northern_mariana_islands'
     52     OHIO                     = 'ohio'
     53     OKLAHOMA                 = 'oklahoma'
     54     OREGON                   = 'oregon'
     55     PENNSYLVANIA             = 'pennsylvania'
     56     PUERTO_RICO              = 'puerto_rico'
     57     RHODE_ISLAND             = 'rhode_island'
     58     SOUTH_CAROLINA           = 'south_carolina'
     59     SOUTH_DAKOTA             = 'south_dakota'
     60     TENNESSEE                = 'tennessee'
     61     TEXAS                    = 'texas'
     62     UTAH                     = 'utah'
     63     US_VIRGIN_ISLANDS        = 'us_virgin_islands'
     64     VERMONT                  = 'vermont'
     65     VIRGINIA                 = 'virginia'
     66     WAKE_ISLAND              = 'wake_island'
     67     WASHINGTON               = 'washington'
     68     WEST_VIRGINIA            = 'west_virginia'
     69     WISCONSIN                = 'wisconsin'
     70     WYOMING                  = 'wyoming'
     71 
     72 
     73 class CommunicationType(str, Enum):
     74     '''List of valid communication types'''
     75 
     76     ABS  = 'ABS'  # Audio Bridge Service
     77     ALLD = 'ALLD' # All Distance
     78     COAX = 'COAX' # Cable TV provider of local exchange
     79     VOIP = 'VOIP' # Interconnected VoIP
     80     CAP  = 'CAP'  # CAP/LEC
     81     CEL  = 'CEL'  # Cellular/PCS/SMR
     82     DAT  = 'DAT'  # Wireless Data
     83     IXC  = 'IXC'  # Interexchange Carrier
     84     LEC  = 'LEC'  # Incumbent Local Exchange Carrier
     85     LRES = 'LRES' # Local Reseller
     86     OSP  = 'OSP'  # Operator Service Provider
     87     OTHL = 'OTHL' # Other Local
     88     OTHM = 'OTHM' # Other Mobile
     89     OTHT = 'OTHT' # Other Toll
     90     PAG  = 'PAG'  # Paging & Messaging
     91     PAY  = 'PAY'  # Payphone Service Provider
     92     PRE  = 'PRE'  # Prepaid Card
     93     PRIV = 'PRIV' # Private Service Provider
     94     SAT  = 'SAT'  # Satellite
     95     SMR  = 'SMR'  # SMR (dispatch)
     96     TEN  = 'TEN'  # Shared Tenant Service Provider
     97     TRES = 'TRES' # Toll Reseller
     98 
     99 
    100 class LogicalOperator(str, Enum):
    101     '''List of valid logical operators'''
    102 
    103     AND = 'AND'
    104     OR  = 'OR'
    105 
    106 
    107 class FCC499Client:
    108     '''FCC Form 499 API Client'''
    109 
    110     # FCC Form 499 API URL
    111     BASE_URL = 'http://apps.fcc.gov/cgb/form499/499results.cfm'
    112     
    113 
    114     def search(self, filer_id=None, legal_name=None, frn=None, states=None, comm_type=None, logical_operator=LogicalOperator.AND):
    115         '''
    116         Search the FCC Form 499 Filer Database
    117         
    118         :param filer_id: str - The FCC Form 499 Filer ID
    119         :param legal_name: str - The legal name of the filer
    120         :param frn: str - The FRN of the filer
    121         :param states: list[States] - The states to search for
    122         :param comm_type: CommunicationType - The communication type to search for
    123         :param logical_operator: LogicalOperator - The logical operator to use
    124         '''
    125         
    126         # Set the default parameters
    127         params = {'XML': 'TRUE', 'R1': logical_operator.value}
    128         
    129         # Add the parameters to the request
    130         if filer_id:
    131             params['FilerID'] = filer_id
    132         if legal_name:
    133             params['LegalName'] = legal_name
    134         if frn:
    135             params['frn'] = frn
    136         if states:
    137             params['state'] = ','.join(state.value for state in states)
    138         if comm_type:
    139             params['comm_type'] = comm_type.value
    140             
    141         # Build the URL
    142         url = f'{self.BASE_URL}?{urllib.parse.urlencode(params)}'
    143         
    144         # Make the request
    145         try:
    146             with urllib.request.urlopen(url) as response:
    147                 if response.status != 200:
    148                     raise ValueError(f'API request failed with status code: {response.status}')
    149                 return response.read().decode('utf-8')
    150         except urllib.error.HTTPError as e:
    151             raise ValueError(f'API request failed with status code: {e.code}')
    152         except urllib.error.URLError as e:
    153             raise ValueError(f'API request failed: {str(e)}')
    154 
    155 
    156 def main():
    157     client = FCC499Client()
    158     
    159     try:
    160         result = client.search(states=[States.MONTANA], comm_type=CommunicationType.OTHM)
    161         print(result)        
    162     except Exception as e:
    163         print(f'Error: {str(e)}')
    164 
    165 
    166 if __name__ == '__main__':
    167     main()