Mechanical Edits/Mateusz Konieczny - bot account/fix overly verbose Euronet Sp. z o.o.

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=Euronet Sp. z o.o. -> operator=Euronet

Why

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

Numbers

1222 - per https://taginfo.openstreetmap.org/keys/operator#values

How

  • Editing is limited to objects in Poland.

state before a mechanical edit:

state after a mechanical edit:

example based on https://www.openstreetmap.org/node/5120853094

Bot source code

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

from osm_bot_abstraction_layer.generic_bot_retagging import run_simple_retagging_task

def transformation():
    return {
        'from': {"operator": "Euronet Sp. z o.o."},
        'to': {"operator": "Euronet"},
    }

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=Euronet Sp. z o.o. -> operator=Euronet (automatyczna edycja)',
        discussion_url='https://forum.openstreetmap.org/viewtopic.php?pid=800371',
        osm_wiki_documentation_page='https://wiki.openstreetmap.org/wiki/Mechanical_Edits/Mateusz_Konieczny_-_bot_account/fix_overly_verbose_Euronet_Sp._z_o.o.',
        edit_element_function=edit_element,
    )

main(transformation())

Discussion

Discussed with Polish OSM community at https://forum.openstreetmap.org/viewtopic.php?id=70513 and in addition at https://t.me/OpenStreetMapPolska/2379

Repetition

One time run.

Opt-out

Please write at https://forum.openstreetmap.org/viewtopic.php?pid=747880 . In case of opt-outs exactly such edit will be made manually.