Mechanical Edits/kubahahaha - bot account/auto rename secondary schools
Page content created as advised on Automated_Edits_code_of_conduct#Document_and_discuss_your_plans.
Who
I, kubahahaha using my bot account
contact
message via OSM I will try to respond also to PMs to the bot account.
What
Removing secondary schools in Poland wherever they match with government registry.
Data preparation
- Download data from this webpage. It's public data available to use. In my work I used version from 20.05.2020. Save file as
registery.xlsx
. - Download list of old secondary schools present in OSM database. I used Overpass api and saved results to
secondary-schools.geojson
. Query I used:
area["name"="Polska (ląd)"]->.boundaryarea; ( nwr(area.boundaryarea)["amenity"="school"]["name"~"Gimnazjum",i]; ); out center;
- My script is available here.
- After running script you should get
result.geojson
anddown.txt
. - Put content of down.txt into code from Bot source code section. Its list of OSM objects to download.
- Run bot.
Why
Secondary schools are closed for almost a year in Poland.
Numbers
199 places out of 393 schools labeled "gimnazjum" with address on OSM in Poland
How
- Editing is limited to objects with name=/*gimnazjum*/i
- Editing is limited to objects with filled address
- Editing is limited to objects in Poland
- Editing is limited to objects with address matching exactly one item from government registry.
state before a mechanical edit:
state after a mechanical edit (list of tags to overwrite using government registry):
- amenity=school
- name=Szkoła podstawowa nr 2
- operator=Gmina Piekary Śląskie
- phone=+48 123 456 789
- email=school@email.com
- website=http://example.com
- isced:level=1;2
Bot source code
Bot is using prepared files with list of corrected schools (available here) and list of OSM ids to fix.
Bot is using https://github.com/matkoniecz/osm_bot_abstraction_layer library, this code is CC0 licensed
from osm_bot_abstraction_layer.generic_bot_retagging import run_simple_retagging_task import json def edit_element(tags): if(tags == {}): return tags fixed = json.load(open('result.geojson',)).get('features') shortlist = list(filter(lambda it: it.get('properties').get('addr:city') == tags.get('addr:city') and it.get('properties').get('addr:street') == tags.get('addr:street') and it.get('properties').get('addr:housenumber') == tags.get('addr:housenumber'), fixed)) correct = shortlist[0]['properties'] tags.update({k:v for k,v in correct.items() if k in ['name', 'operator', 'phone', 'email', 'website', 'isced:level']}) return tags def main(): run_simple_retagging_task( max_count_of_elements_in_one_changeset=500, objects_to_consider_query=""" [out:xml][timeout:25000]; ( node(id:307933883, 321001769, 372191800, 581905258, 584458427, 584461607, 584469043, 584472679, 683191158, 710646387, 914431837, 938167761, 968360638, 1179548366, 1406784222, 1409592681, 1410900251, 1425053621, 1433598762, 1469599164, 1595351956, 1597823261, 1726085481, 1745826204, 1821279974, 1826049774, 1827073816, 1862022628, 1889538407, 1897273481, 1900721407, 1900835485, 1903963148, 1903963152, 1927559893, 1934517761, 1940473968, 1940473988, 1940474064, 1983293837, 2007384418, 2080923833, 2120667598, 2148890405, 2151820733, 2208464328, 2310068439, 2319923830, 2360116191, 2371023582, 2450851151, 2471818959, 2484470491, 2499688943, 2499942355, 2547433073, 2630775004, 2687664453, 2816310227, 2857860875, 2876203849, 2918977305, 2933593935, 2946468977, 2986705035, 2986759353, 2986759354, 2986759357, 2986759359, 2986759361, 2986759363, 2986759364, 2986977686, 2986977688, 2986977690, 2986977691, 2986977692, 2986977693, 2986977694, 2989928312, 3015786031, 3027224233, 3056292246, 3056450491, 3056491714, 3058132043, 3061834983, 3073673590, 3079112564, 3085278729, 3110256211, 3149800172, 3241093484, 3298417068, 3298417069, 3387662684, 3387662685, 3387664594, 3387664595, 3419393584, 3730308425, 3732562443, 3888189056, 3907794042, 3915431458, 3921303464, 3932235046, 4277820906, 4338991226, 4537601561, 4608331037, 4678970352, 4866124703, 4916966796, 5065839322); way(id:61190465, 66577674, 81114300, 115911875, 121190458, 143896474, 147421095, 148642115, 149140779, 151523732, 165786001, 167913482, 168655777, 170011795, 170011796, 170089758, 171897217, 176536980, 177322360, 177594577, 179612940, 182058035, 183557816, 183637237, 183637241, 187719855, 189055541, 193028869, 199265700, 203463451, 208303161, 210967799, 220851554, 221182466, 222194694, 231836472, 233354993, 234782938, 237989506, 241234924, 241454541, 245537604, 246079211, 249314260, 253262682, 256332478, 259216756, 264033502, 268694591, 272678827, 279334101, 283860351, 288775618, 291432704, 295995795, 296707573, 297519343, 299375410, 302344283, 309206752, 311119631, 330901396, 338066017, 364671094, 375719635, 375871281, 381806345, 390593598, 400852287, 401810845, 409235663, 417416927, 436826615, 438084564, 460194664, 462419296, 514614927, 537007463, 625992554, 629189477, 696033045); relation(id:2718947, 3421861, 5174292); ); out body; >; out skel qt; """, objects_to_consider_query_storage_file='/tmp/work.osm', is_in_manual_mode=True, changeset_comment='Usuwanie gimnazjów - aktualizacja na podstawie Wykazu szkół i placówek oświatowych tam gdzie to możliwe', discussion_url='https://forum.openstreetmap.org/viewtopic.php?id=797497', edit_element_function=edit_element, osm_wiki_documentation_page='https://wiki.openstreetmap.org/wiki/Mechanical_Edits/kubahahaha_-_bot_account/auto_rename_secondary_schools' ) main()
Discussion
Polish forum: Topic does not exist anymore
Repetition
This is one time task