Skip to content

Commit ec30ee1

Browse files
authored
Merge pull request #42 from eyeseast/capture-raw
Raw results in geocode_table, too
2 parents 50f9f06 + 807faa5 commit ec30ee1

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Diff for: geocode_sqlite/utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def geocode_table(
5656
log.info(f"Adding longitude column: {longitude_column}")
5757
table.add_column(longitude_column, float)
5858

59+
if raw and raw != "raw":
60+
log.info(f"Using custom raw result field: {raw}")
61+
62+
if raw and raw not in columns:
63+
log.info(f"Adding {raw} column")
64+
table.add_column(raw, str)
65+
5966
if geojson and GEOMETRY_COLUMN not in columns:
6067
log.info("Adding geometry column")
6168
table.add_column(GEOMETRY_COLUMN, str)
@@ -107,6 +114,9 @@ def geocode_table(
107114
update[latitude_column] = result.latitude
108115
update[longitude_column] = result.longitude
109116

117+
if raw:
118+
update[raw] = result.raw
119+
110120
table.update(pk, update, conversions=conversions)
111121
count += 1
112122

Diff for: tests/test_geocode_sqlite.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ def test_capture_raw(db, db_path, geocoder):
416416
],
417417
)
418418

419-
print(result.stdout)
420419
assert 0 == result.exit_code
421420

422421
for row in table.rows:
@@ -457,7 +456,6 @@ def test_capture_raw_custom(db, db_path, geocoder):
457456
],
458457
)
459458

460-
print(result.stdout)
461459
assert 0 == result.exit_code
462460

463461
for row in table.rows:
@@ -467,3 +465,27 @@ def test_capture_raw_custom(db, db_path, geocoder):
467465
result = geo_table.get(row["id"])
468466

469467
assert raw == result
468+
469+
470+
def test_geocode_table_raw(db, geocoder):
471+
table = db[TABLE_NAME]
472+
geo_table = db[GEO_TABLE]
473+
474+
RAW = "raw"
475+
476+
assert "latitude" not in table.columns_dict
477+
assert "longitude" not in table.columns_dict
478+
assert "raw" not in table.columns_dict
479+
480+
count = geocode_table(db, TABLE_NAME, geocoder, "{id}", raw=RAW)
481+
482+
# did we get the whole table?
483+
assert count == table.count
484+
485+
for row in table.rows:
486+
assert type(row.get(RAW)) == str
487+
488+
raw = json.loads(row[RAW])
489+
result = geo_table.get(row["id"])
490+
491+
assert raw == result

0 commit comments

Comments
 (0)