Download fcc tower data in script rather than expecting it present

This commit is contained in:
Chandler Swift 2026-03-03 22:35:59 -06:00
parent c9b033a61e
commit 1e3b67ebdd
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F

View file

@ -5,6 +5,7 @@ import csv
import io import io
import json import json
import zipfile import zipfile
import urllib.request
fieldnames = { fieldnames = {
"CO": ("Record Type", "Content Indicator", "File Number", "Registration Number", "Unique System Identifier", "CO": ("Record Type", "Content Indicator", "File Number", "Registration Number", "Unique System Identifier",
@ -15,8 +16,8 @@ fieldnames = {
} }
filenames = ["CO", "EN", "HS", "RA", "RE", "SC"] filenames = ["CO", "EN", "HS", "RA", "RE", "SC"]
files = {} files = {}
resp = urllib.request.urlopen("https://data.fcc.gov/download/pub/uls/complete/r_tower.zip")
with zipfile.ZipFile("r_tower.zip", "r") as z: with zipfile.ZipFile(io.BytesIO(resp.read())) as z:
for filename in filenames: for filename in filenames:
with z.open(f"{filename}.dat", "r") as f, io.TextIOWrapper( # Avoids `_csv.Error: iterator should return strings, not bytes (the file should be opened in text mode)` with z.open(f"{filename}.dat", "r") as f, io.TextIOWrapper( # Avoids `_csv.Error: iterator should return strings, not bytes (the file should be opened in text mode)`
f, encoding="utf-8", newline="", errors="replace" f, encoding="utf-8", newline="", errors="replace"