@@ -427,7 +427,10 @@ def update_osm_enrich_from_api_in_batch(
427
427
self .info ('%s' % e )
428
428
return content
429
429
430
- def process_empty_changeset_from_table (self , table_name , table_columns , osm_id_column , osm_type ):
430
+ def process_empty_changeset_from_table (
431
+ self , table_name , table_columns ,
432
+ osm_id_column , osm_type , extra_where = None
433
+ ):
431
434
""" Processing all data from table
432
435
433
436
:param table_name: Table source
@@ -444,15 +447,25 @@ def process_empty_changeset_from_table(self, table_name, table_columns, osm_id_c
444
447
445
448
:param osm_id_column: Column name of osm_id
446
449
:type osm_id_column: str
450
+
451
+ :param extra_where: Other where for query
452
+ :type extra_where: str
447
453
"""
448
454
# noinspection PyUnboundLocalVariable
449
455
connection = self .create_connection ()
450
456
cursor = connection .cursor ()
451
457
row_batch = {}
452
458
osm_ids = []
453
459
try :
454
- check_sql = ''' select * from %s."%s" WHERE "changeset_timestamp"
455
- IS NULL AND "osm_id" IS NOT NULL ORDER BY "osm_id" ''' % (self .default ['DBSCHEMA_PRODUCTION' ], table_name )
460
+ check_sql = f'''
461
+ select * from { self .default ['DBSCHEMA_PRODUCTION' ]} .{ table_name } WHERE "changeset_timestamp"
462
+ IS NULL AND "{ osm_id_column } " IS NOT NULL
463
+ '''
464
+ if extra_where :
465
+ check_sql += f' AND { extra_where } '
466
+
467
+ check_sql += f''' ORDER BY "{ osm_id_column } "'''
468
+
456
469
cursor .execute (check_sql )
457
470
row = True
458
471
while row :
@@ -461,10 +474,15 @@ def process_empty_changeset_from_table(self, table_name, table_columns, osm_id_c
461
474
if row :
462
475
row = dict (zip (table_columns , row ))
463
476
row_batch ['%s' % row [osm_id_column ]] = row
464
- osm_ids .append ('%s' % row [osm_id_column ])
465
- if len (osm_ids ) == 30 :
477
+ try :
478
+ osm_ids .append (f'{ abs (row [osm_id_column ])} ' )
479
+ except :
480
+ osm_ids .append ('%s' % row [osm_id_column ])
481
+ if len (osm_ids ) == 20 :
466
482
self .update_osm_enrich_from_api_in_batch (
467
- osm_ids , osm_type , row_batch , table_name , osm_id_column )
483
+ osm_ids , osm_type , row_batch , table_name ,
484
+ osm_id_column
485
+ )
468
486
row_batch = {}
469
487
osm_ids = []
470
488
@@ -484,9 +502,22 @@ def enrich_empty_changeset(self):
484
502
osm_type = table_data ['osm_type' ]
485
503
columns = table_data ['columns' ]
486
504
if osm_id_columnn is not None :
487
- self .info ('Checking data from table %s' % table )
488
- self .process_empty_changeset_from_table (
489
- table , columns , osm_id_columnn , osm_type )
505
+ if osm_type == 'way' :
506
+ self .info ('Checking data from table %s with type way' % table )
507
+ self .process_empty_changeset_from_table (
508
+ table , columns , osm_id_columnn , 'way' ,
509
+ extra_where = f'"{ osm_id_columnn } " > 0'
510
+ )
511
+ self .info ('Checking data from table %s with type relation' % table )
512
+ self .process_empty_changeset_from_table (
513
+ table , columns , osm_id_columnn , 'relation' ,
514
+ extra_where = f'"{ osm_id_columnn } " < 0'
515
+ )
516
+ else :
517
+ self .info ('Checking data from table %s' % table )
518
+ self .process_empty_changeset_from_table (
519
+ table , columns , osm_id_columnn , osm_type
520
+ )
490
521
else :
491
522
self .info ('Does not know osm_id column for %s.' % table )
492
523
0 commit comments