Commit 689f661e authored by Branko Kokanovic's avatar Branko Kokanovic

fix apartment simple tool

parent 2f4a5bb0
......@@ -4,3 +4,5 @@ stambene-jedinice-analysis.log*
result.csv
progress.pickle
index.html
osm-password
fixes.log*
import csv
import logging
import logging.handlers
import osmapi
def setup_logger(filename: str):
"""Simple logger used throughout whole scrapper - logs both to file and console."""
logging_level = logging.INFO
l = logging.getLogger()
l.setLevel(logging_level)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch = logging.handlers.TimedRotatingFileHandler(filename=filename, when='midnight', interval=1)
ch.setLevel(logging_level)
ch.setFormatter(formatter)
l.addHandler(ch)
ch = logging.StreamHandler()
ch.setLevel(logging_level)
ch.setFormatter(formatter)
l.addHandler(ch)
return l
logger = setup_logger('fixes.log')
api = osmapi.OsmApi(passwordfile='osm-password',
changesetauto=True, changesetautosize=50, changesetautotags=
{u"comment": u"Serbian lint bot "
"(https://gitlab.com/stalker314314/stambene-zajednice-analysis). "
"Adding building=apartments on government provided open dataset",
u"tag": u"mechanical=yes"})
def load_results():
stambene_zajednice = []
with open('result.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
sz = {}
sz['district'] = row['district']
sz['municipality'] = row['municipality']
sz['street'] = row['street']
sz['number'] = row['number']
sz['processed'] = True
sz['node'] = None if row['node'] == '' else int(row['node'])
sz['way'] = None if row['way'] == '' else int(row['way'])
sz['multiple_entities_same_housenumber'] = row['multiple_entities_same_housenumber'] == 'True'
sz['building_tag_present'] = row['building_tag_present'] == 'True'
sz['building_is_apartments'] = row['building_is_apartments'] == 'True'
stambene_zajednice.append(sz)
return stambene_zajednice
def main():
stambene_zajednice = load_results()
count = len([sz for sz in stambene_zajednice
if sz['processed'] and sz['way'] and sz['building_tag_present'] and not sz['building_is_apartments']])
i = 0
for sz in stambene_zajednice:
if sz['processed'] and sz['way'] and sz['building_tag_present'] and not sz['building_is_apartments']:
i = i + 1
logger.info('Progress: {0}/{1}'.format(i, count))
if i < 20: # Skip already processed
continue
way = api.WayGet(sz['way'])
if 'building' not in way['tag']:
logger.warning('{0} is missing building tag, skipping'.format(sz['way']))
continue
if way['tag']['building'] == 'apartments':
logger.warning('{0} already have building=apartments tag, skipping'.format(sz['way']))
continue
for k, v in way['tag'].items():
logger.info('{0}: {1}'.format(k, v))
logger.info('https://www.openstreetmap.org/way/{0}'.format(sz['way']))
to_continue = input('Proceed (y/n):')
if to_continue == 'y':
way['tag']['building'] = 'apartments'
api.WayUpdate(way)
api.flush()
if __name__ == '__main__':
main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment