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 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"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue