forked from hans/Nominatim
more formatting fixes
Found by flake8.
This commit is contained in:
@@ -103,7 +103,7 @@ class CommandlineParser:
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
##### Subcommand classes
|
# Subcommand classes
|
||||||
#
|
#
|
||||||
# Each class needs to implement two functions: add_args() adds the CLI parameters
|
# Each class needs to implement two functions: add_args() adds the CLI parameters
|
||||||
# for the subfunction, run() executes the subcommand.
|
# for the subfunction, run() executes the subcommand.
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class UpdateRefresh:
|
|||||||
args.threads or 1)
|
args.threads or 1)
|
||||||
indexer.index_postcodes()
|
indexer.index_postcodes()
|
||||||
else:
|
else:
|
||||||
LOG.error("The place table doesn\'t exist. " \
|
LOG.error("The place table doesn't exist. "
|
||||||
"Postcode updates on a frozen database is not possible.")
|
"Postcode updates on a frozen database is not possible.")
|
||||||
|
|
||||||
if args.word_counts:
|
if args.word_counts:
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ def _check(hint=None):
|
|||||||
"""
|
"""
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
title = func.__doc__.split('\n', 1)[0].strip()
|
title = func.__doc__.split('\n', 1)[0].strip()
|
||||||
|
|
||||||
def run_check(conn, config):
|
def run_check(conn, config):
|
||||||
print(title, end=' ... ')
|
print(title, end=' ... ')
|
||||||
ret = func(conn, config)
|
ret = func(conn, config)
|
||||||
@@ -98,13 +99,12 @@ def _get_indexes(conn):
|
|||||||
if conn.table_exists('place'):
|
if conn.table_exists('place'):
|
||||||
indexes.extend(('idx_placex_pendingsector',
|
indexes.extend(('idx_placex_pendingsector',
|
||||||
'idx_location_area_country_place_id',
|
'idx_location_area_country_place_id',
|
||||||
'idx_place_osm_unique'
|
'idx_place_osm_unique'))
|
||||||
))
|
|
||||||
|
|
||||||
return indexes
|
return indexes
|
||||||
|
|
||||||
|
|
||||||
### CHECK FUNCTIONS
|
# CHECK FUNCTIONS
|
||||||
#
|
#
|
||||||
# Functions are exectured in the order they appear here.
|
# Functions are exectured in the order they appear here.
|
||||||
|
|
||||||
|
|||||||
@@ -184,8 +184,10 @@ def truncate_data_tables(conn):
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
_COPY_COLUMNS = 'osm_type, osm_id, class, type, name, admin_level, address, extratags, geometry'
|
_COPY_COLUMNS = 'osm_type, osm_id, class, type, name, admin_level, address, extratags, geometry'
|
||||||
|
|
||||||
|
|
||||||
def load_data(dsn, threads):
|
def load_data(dsn, threads):
|
||||||
""" Copy data into the word and placex table.
|
""" Copy data into the word and placex table.
|
||||||
"""
|
"""
|
||||||
@@ -250,6 +252,7 @@ def create_search_indices(conn, config, drop=False):
|
|||||||
|
|
||||||
sql.run_sql_file(conn, 'indices.sql', drop=drop)
|
sql.run_sql_file(conn, 'indices.sql', drop=drop)
|
||||||
|
|
||||||
|
|
||||||
def create_country_names(conn, tokenizer, languages=None):
|
def create_country_names(conn, tokenizer, languages=None):
|
||||||
""" Add default country names to search index. `languages` is a comma-
|
""" Add default country names to search index. `languages` is a comma-
|
||||||
separated list of language codes as used in OSM. If `languages` is not
|
separated list of language codes as used in OSM. If `languages` is not
|
||||||
@@ -261,8 +264,7 @@ def create_country_names(conn, tokenizer, languages=None):
|
|||||||
|
|
||||||
def _include_key(key):
|
def _include_key(key):
|
||||||
return key == 'name' or \
|
return key == 'name' or \
|
||||||
(key.startswith('name:') \
|
(key.startswith('name:') and (not languages or key[5:] in languages))
|
||||||
and (not languages or key[5:] in languages))
|
|
||||||
|
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
psycopg2.extras.register_hstore(cur)
|
psycopg2.extras.register_hstore(cur)
|
||||||
|
|||||||
@@ -142,7 +142,8 @@ def change_housenumber_transliteration(conn, **_):
|
|||||||
BEGIN
|
BEGIN
|
||||||
SELECT array_to_string(array_agg(trans), ';')
|
SELECT array_to_string(array_agg(trans), ';')
|
||||||
INTO normtext
|
INTO normtext
|
||||||
FROM (SELECT lookup_word as trans, getorcreate_housenumber_id(lookup_word)
|
FROM (SELECT lookup_word as trans,
|
||||||
|
getorcreate_housenumber_id(lookup_word)
|
||||||
FROM (SELECT make_standard_name(h) as lookup_word
|
FROM (SELECT make_standard_name(h) as lookup_word
|
||||||
FROM regexp_split_to_table(housenumber, '[,;]') h) x) y;
|
FROM regexp_split_to_table(housenumber, '[,;]') h) x) y;
|
||||||
return normtext;
|
return normtext;
|
||||||
|
|||||||
@@ -166,10 +166,13 @@ def update_postcodes(dsn, project_dir, tokenizer):
|
|||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT cc as country_code, pc, ST_X(centroid), ST_Y(centroid)
|
SELECT cc as country_code, pc, ST_X(centroid), ST_Y(centroid)
|
||||||
FROM (SELECT
|
FROM (SELECT
|
||||||
COALESCE(plx.country_code, get_country_code(ST_Centroid(pl.geometry))) as cc,
|
COALESCE(plx.country_code,
|
||||||
|
get_country_code(ST_Centroid(pl.geometry))) as cc,
|
||||||
token_normalized_postcode(pl.address->'postcode') as pc,
|
token_normalized_postcode(pl.address->'postcode') as pc,
|
||||||
ST_Centroid(ST_Collect(COALESCE(plx.centroid, ST_Centroid(pl.geometry)))) as centroid
|
ST_Centroid(ST_Collect(COALESCE(plx.centroid,
|
||||||
FROM place AS pl LEFT OUTER JOIN placex AS plx ON pl.osm_id = plx.osm_id AND pl.osm_type = plx.osm_type
|
ST_Centroid(pl.geometry)))) as centroid
|
||||||
|
FROM place AS pl LEFT OUTER JOIN placex AS plx
|
||||||
|
ON pl.osm_id = plx.osm_id AND pl.osm_type = plx.osm_type
|
||||||
WHERE pl.address ? 'postcode' AND pl.geometry IS NOT null
|
WHERE pl.address ? 'postcode' AND pl.geometry IS NOT null
|
||||||
GROUP BY cc, pc) xx
|
GROUP BY cc, pc) xx
|
||||||
WHERE pc IS NOT null AND cc IS NOT null
|
WHERE pc IS NOT null AND cc IS NOT null
|
||||||
|
|||||||
@@ -174,10 +174,10 @@ class SPImporter():
|
|||||||
|
|
||||||
if table_name in self.table_phrases_to_delete:
|
if table_name in self.table_phrases_to_delete:
|
||||||
self.statistics_handler.notify_one_table_ignored()
|
self.statistics_handler.notify_one_table_ignored()
|
||||||
#Remove this table from the ones to delete as it match a class/type
|
# Remove this table from the ones to delete as it match a
|
||||||
#still existing on the special phrases of the wiki.
|
# class/type still existing on the special phrases of the wiki.
|
||||||
self.table_phrases_to_delete.remove(table_name)
|
self.table_phrases_to_delete.remove(table_name)
|
||||||
#So dont need to create the table and indexes.
|
# So don't need to create the table and indexes.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Table creation
|
# Table creation
|
||||||
@@ -248,10 +248,12 @@ class SPImporter():
|
|||||||
Delete the place_classtype tables.
|
Delete the place_classtype tables.
|
||||||
"""
|
"""
|
||||||
LOG.warning('Cleaning database...')
|
LOG.warning('Cleaning database...')
|
||||||
#Array containing all queries to execute. Contain tuples of format (query, parameters)
|
# Array containing all queries to execute.
|
||||||
|
# Contains tuples of format (query, parameters)
|
||||||
queries_parameters = []
|
queries_parameters = []
|
||||||
|
|
||||||
#Delete place_classtype tables corresponding to class/type which are not on the wiki anymore
|
# Delete place_classtype tables corresponding to class/type which
|
||||||
|
# are not on the wiki anymore.
|
||||||
for table in self.table_phrases_to_delete:
|
for table in self.table_phrases_to_delete:
|
||||||
self.statistics_handler.notify_one_table_deleted()
|
self.statistics_handler.notify_one_table_deleted()
|
||||||
query = SQL('DROP TABLE IF EXISTS {}').format(Identifier(table))
|
query = SQL('DROP TABLE IF EXISTS {}').format(Identifier(table))
|
||||||
|
|||||||
@@ -65,5 +65,6 @@ class SPWikiLoader(Iterator):
|
|||||||
Requested URL Example :
|
Requested URL Example :
|
||||||
https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/EN
|
https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/EN
|
||||||
"""
|
"""
|
||||||
url = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/' + lang.upper() # pylint: disable=line-too-long
|
url = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/' \
|
||||||
|
+ lang.upper()
|
||||||
return get_url(url)
|
return get_url(url)
|
||||||
|
|||||||
Reference in New Issue
Block a user