Skip to content

Commit 56c2cf0

Browse files
committed
PR feedback plus one bug fix
1 parent f920bdc commit 56c2cf0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

data/wof_snapshot.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,20 @@ def add_sqlite_file(self, sqlite_filename, file_hash):
7171

7272
cursor = conn.cursor()
7373
pbar.update(1)
74-
cursor.execute("select body from geojson where geojson.id in (select id from spr where placetype IN ('neighbourhood', 'borough','macrohood', 'microhood')) and geojson.is_alt=0")
74+
query = """
75+
select geojson.body from geojson where geojson.id in (
76+
select spr.id from spr
77+
where spr.placetype IN ('neighbourhood', 'borough','macrohood', 'microhood')
78+
AND spr.id != 1
79+
AND spr.is_deprecated = 0
80+
AND spr.is_superseded = 0
81+
AND spr.is_current != 0
82+
) AND geojson.is_alt = 0
83+
"""
84+
cursor.execute(query)
7585
pbar.update(1)
7686

77-
rows = cursor.fetchall()
78-
pbar.update(1)
79-
80-
for row in rows:
87+
for row in cursor:
8188
n_or_fail = _parse_neighbourhood_from_json(row[0])
8289
self.handle_neighborhood_or_fail(n_or_fail)
8390
pbar.update(1)
@@ -123,7 +130,7 @@ def __init__(self, filename):
123130
suffix_length = len(".bz2")
124131
input_filename = filename[:filename.rfind("/")+1]
125132
output_filename = filename[:-suffix_length]
126-
with tqdm(desc="Decompressing " % input_filename, unit="bytes", unit_scale=True) as pbar:
133+
with tqdm(desc="Decompressing %s" % input_filename, unit="bytes", unit_scale=True) as pbar:
127134
with open(output_filename, 'w') as outfile:
128135
with bz2.BZ2File(filename, 'r') as bzfile:
129136
for chunk in bzfile:
@@ -146,7 +153,7 @@ def __exit__(self, type, value, traceback):
146153
reader = WOFArchiveReader()
147154

148155
with tmpdownload(WOF_SQLITE) as fname:
149-
with TmpBz2Decompress(fname) as decompressed:
156+
with TmpBz2Decompress(fname) as decompressed:
150157
reader.add_sqlite_file(decompressed, "latest")
151158

152159
print "Writing output SQL"

0 commit comments

Comments
 (0)