Download fcc tower data in script rather than expecting it present
This commit is contained in:
parent
c9b033a61e
commit
1e3b67ebdd
1 changed files with 3 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ import csv
|
|||
import io
|
||||
import json
|
||||
import zipfile
|
||||
import urllib.request
|
||||
|
||||
fieldnames = {
|
||||
"CO": ("Record Type", "Content Indicator", "File Number", "Registration Number", "Unique System Identifier",
|
||||
|
|
@ -15,8 +16,8 @@ fieldnames = {
|
|||
}
|
||||
filenames = ["CO", "EN", "HS", "RA", "RE", "SC"]
|
||||
files = {}
|
||||
|
||||
with zipfile.ZipFile("r_tower.zip", "r") as z:
|
||||
resp = urllib.request.urlopen("https://data.fcc.gov/download/pub/uls/complete/r_tower.zip")
|
||||
with zipfile.ZipFile(io.BytesIO(resp.read())) as z:
|
||||
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)`
|
||||
f, encoding="utf-8", newline="", errors="replace"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue