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