Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect fieldname "dbname" and using JSON content between processors #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addok_psql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Import from PostgreSQL into addok."
VERSION = (0, 1, 0)
VERSION = (0, 1, 1)

__author__ = 'Yohan Boniface'
__contact__ = "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion addok_psql/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PSQL = {
'dbname': 'nominatim'
'database': 'nominatim'
}
PSQL_PROCESSORS = (
'addok_psql.processors.query',
Expand Down
5 changes: 3 additions & 2 deletions addok_psql/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def preprocess():

def process(args):
print('Import from Postgresql')
keys = ['dbname', 'user', 'host', 'port']
keys = ['dbname', 'user', 'host', 'port', 'password']
for key in keys:
value = getattr(args, key, None)
if value:
Expand All @@ -32,6 +32,7 @@ def register_command(subparsers):
parser.set_defaults(func=process)
parser.add_argument('--host', help='PostgreSQL host')
parser.add_argument('--user', help='PostgreSQL user')
parser.add_argument('--dbname', help='PostgreSQL name')
parser.add_argument('--dbname', help='PostgreSQL database name')
parser.add_argument('--password', help='PostgreSQL password user')
parser.add_argument('--port', help='PostgreSQL port')
parser.add_argument('--limit', help='Limit retrieved rows')
21 changes: 11 additions & 10 deletions addok_psql/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import psycopg2
import psycopg2.extras

import psycopg2
import psycopg2.extras
import json

from addok.config import config
from addok.helpers import yielder
Expand All @@ -27,16 +25,17 @@ def query(*args):
print('Query executed with itersize', cur.itersize)

for row in cur.__iter__():
yield dict(row)
yield json.dumps(dict(row))
cur.close()


@yielder
def get_context(row):
def get_context(raw):
row = json.loads(raw)
if "context" not in row:
row['context'] = []
add_parent(row, row)
return row
return json.dumps(row)


def add_parent(child, row):
Expand All @@ -63,7 +62,8 @@ def add_parent_data(parent, row):


@yielder
def get_housenumbers(row):
def get_housenumbers(raw):
row = json.loads(raw)
if row['class'] == 'highway':
sql = """SELECT housenumber, ST_X(ST_Centroid(geometry)) as lon,
ST_Y(ST_Centroid(geometry)) as lat
Expand All @@ -79,11 +79,12 @@ def get_housenumbers(row):
hn['housenumber']: {'lat': hn['lat'], 'lon': hn['lon']}
for hn in housenumbers
}
return row
return json.dumps(row)


@yielder
def row_to_doc(row):
def row_to_doc(raw):
row = json.loads(raw)
doc = {
"id": row["osm_type"] + str(row["osm_id"]),
"lat": row['lat'],
Expand Down Expand Up @@ -116,4 +117,4 @@ def row_to_doc(row):
row['source'] = 'OSM'
# See https://wiki.osm.org/wiki/Nominatim/Development_overview#Country_to_street_level # noqa
doc['importance'] = (row.get('rank_search', 30) / 30) * 0.1
return doc
return json.dumps(row)