[josm-dev] Change credentials from Python script in JOSM
winfixit at gmail.com
Wed Jan 27 18:29:16 UTC 2016
I'm creating a prototype in Python to add wikidata entries and tags during
an import of schools. To upload the school data, there is this silly rule
that this needs to be done using a separate import account. It doesn't
matter how I feel about this requirement, but my main problem with it, is
that I constantly forget to switch back and forth.
So, what I would like to do is create script that changes to the import
account and uploads the node with the imported data, then switch back to
the regular account and upload buildings, school perimeter and access roads.
As said, I would at the same time, create wikidata item to which I want to
add coordinates and add the node id url as a reference. By doing it right
at the time of the import, I hope to avoid occasional licensing issues.
It would be nice if this could become part of the importing workflow, while
still allowing to upload each item with the proper account.
An example wikidata entry:
The node for the school gets this as:
If you look at the wikidata entry, all the parameters are sourced as
reference URL: http://www.ubos.org
The coordinate location <https://www.wikidata.org/wiki/Property:P625>
is sourced as https://www.openstreetmap.org/node/3966915559
Making it clear where the coordinates came from and easy to jump to it. The
coordinates are georeferenced on Bing though, at the time of upload, or
The reason why I want to make uploading part of my script, is that creating
the wikidata entries becomes a 2 step process. First use all the imported
data to create a wikidata item and have a Q-number. Assign this number to
the wikidata key. Then upload, so the node starts to exist on the
Openstreetmap side and it becomes possible to refer to it when adding the
coordinates to Wikidata.
I hope this makes sense somehow. Anyway, I got stuck on automating the
switching of the accounts.
I can bluntly do the following:
print Main.pref.put("osm-server.username", 'PolyglotImport')
And I see the change happening in preferences.xml
Unsurprisingly, it's not possible to upload anymore after doing this, until
I go into settings and set the osm server url back to its default setting.
Here is the prototype script I'm creating:
The coding style is not great at all and it would be better to use the
wikidata API directly instead of using this kludge via QuickStatements
through the browser. Hopefully somebody may become inspired into turning it
into a proper plugin or add the functionality to the Wikipedia plugin.
More information about the josm-dev