Mechanical Edits/Mateusz Konieczny - bot account/fix overly verbose Santander Bank Polska S.A.

From OpenStreetMap Wiki
Jump to navigation Jump to search

Page content created as advised on Automated_Edits_code_of_conduct#Document_and_discuss_your_plans.

Who

I, Mateusz Konieczny using my bot account

contact

message via OSM I will respond also to PMs to the bot account. In both cases I will be notified about incoming PMs via email and notifications in OSM editors.

What

operator=Santander Bank Polska S.A. -> operator=Santander Bank Polska

Why

Typical tagging by humans will operator=Santander Bank Polska, two variants for one thing just make processing harder (spotted during reviewing SC issues, more specifically - https://github.com/westnordost/StreetComplete/issues/203 )

Numbers

Number large enough that it will save time to use bot

How

  • Editing is limited to objects in Poland.

state before a mechanical edit:

state after a mechanical edit:

Bot source code

Bot is using https://github.com/matkoniecz/osm_bot_abstraction_layer library, this code is GNU AGPL licensed

from osm_bot_abstraction_layer.generic_bot_retagging import run_simple_retagging_task

def transformation():
    return {
        'from': {"operator": "Santander Bank Polska S.A."},
        'to': {"operator": "Santander Bank Polska"},
    }

def edit_element(tags):
    for key, value in transformation()['from'].items():
        if tags.get(key) != (value):
            return tags

    for key in transformation()['from'].keys():
        tags.pop(key, None)

    for key, value in transformation()['to'].items():
        tags[key] = value
    return tags

def escape_overpass_query_text(text):
    return "'" +text.replace("\\", "\\\\").replace("'", "\\'") + "'"

def dictionary_to_overpass_tag_filter(tag_dictionary):
    returned = ""
    for key, value in tag_dictionary.items():
        returned += "[" + escape_overpass_query_text(key) + "=" + escape_overpass_query_text(value) + "]"
    return returned

def main(tag_dictionary):
    run_simple_retagging_task(
        max_count_of_elements_in_one_changeset=500,
        objects_to_consider_query="""
[out:xml][timeout:25000];
(
  nwr""" + dictionary_to_overpass_tag_filter(tag_dictionary['from']) + """;
);
out body;
>;
out skel qt;
""",
        objects_to_consider_query_storage_file='/media/mateusz/OSM_cache/OSM-cache/overpass/retag.osm',
        is_in_manual_mode=False,
        changeset_comment='operator=Santander Bank Polska S.A. -> operator=Santander Bank Polska',
        discussion_url='https://forum.openstreetmap.org/viewtopic.php?id=73921',
        osm_wiki_documentation_page='https://wiki.openstreetmap.org/w/index.php?title=Mechanical_Edits/Mateusz_Konieczny_-_bot_account/fix_overly_verbose_Santander_Bank_Polska_S.A.',
        edit_element_function=edit_element,
    )

main(transformation())

Discussion

Discussed with Polish OSM community at https://forum.openstreetmap.org/viewtopic.php?id=73921

Repetition

One time run.

Opt-out

Please write at abovementioned discussion thread. In case of opt-outs exactly such edit will be made manually.