Skip to content

Add method UserHistory#174

Closed
vazhnov wants to merge 7 commits into
metaodi:developfrom
vazhnov:Add_UserHistory
Closed

Add method UserHistory#174
vazhnov wants to merge 7 commits into
metaodi:developfrom
vazhnov:Add_UserHistory

Conversation

@vazhnov
Copy link
Copy Markdown

@vazhnov vazhnov commented Sep 16, 2024

Add method UserHistory(UserId) which returns all changesets for a user.

Usage example:

import pprint
import osmapi

api = osmapi.OsmApi()
history = api.UserHistory('Alexey%20Vazhnov')
pprint.pprint(history)

Other ways to fetch all changesets for a user:

Closes https://help.openstreetmap.org/questions/23089/ 😄

How to test the code from the branch:

python3 -m venv venv
source venv/bin/activate
pip3 install 'git+https://github.com/vazhnov/osmapi.git@Add_UserHistory'
python3 ./examples/fetch_user_history.py --username 'My%20user' --loglevel WARNING --limit 90 --filename /tmp/MyHistory.json

Questions:

  1. Should I use name user_history instead of UserHistory? Create a more "pythonic" API #39
  2. Should I add to the docstring, that the method can do multiple API calls?
  3. Should I add to the docstring, that limits/defaults, changesets maximum_elements and changesets default_query_limit can be received by capabilities() method from GET /api/capabilities?
  4. Should I remove time.sleep from the code? I use it to reduce a peak load to the API server, but probably it is a premature optimization.

P.S.: I'm not a Python developer. Maybe my code is ugly and wrong — please write a comment or edit the code.

…s for a user

Another ways:
* Web UI: https://www.openstreetmap.org/user/Alexey%20Vazhnov/history
* Manual API request: https://api.openstreetmap.org/api/0.6/changesets?display_name=Alexey%20Vazhnov

Possible improvements:
* add possibility to use `user=#uid` as alternative to current `display_name=UserId`
* URL encoding for `UserId`, for example replace ` ` with %20
* if keep using `return`, maybe use `OrderedDict` to save the order of records
* use `yield` (but then resulting structure will be different)
The default date is 2005-01-01 because of https://www.openstreetmap.org/changeset/1 which is 2005-04-09,
so probably there are no changes earlier in the OSM DB.
@metaodi
Copy link
Copy Markdown
Owner

metaodi commented Oct 8, 2024

@vazhnov I think the API already exists, it's ChangesetsGet, see this test for an example usage.

@vazhnov
Copy link
Copy Markdown
Author

vazhnov commented Dec 30, 2024

@metaodi , thank you for the clue!

I've checked ChangesetsGet — yes it is good, but it can return maximum 100 records.
My UserHistory returns everything (for example, for my user it fetches 5162 edits).

What do you think, should I try to improve ChangesetsGet so it will have similar logic with while need_fetch and calculating time_str_ruby as in https://github.com/vazhnov/osmapi/blob/Add_UserHistory/osmapi/OsmApi.py#L1209-L1231 , instead of writing a new function UserHistory?

Sorry for not responding quickly, it was pretty busy year.

@vazhnov
Copy link
Copy Markdown
Author

vazhnov commented Jul 24, 2025

@metaodi ?

@metaodi
Copy link
Copy Markdown
Owner

metaodi commented Jul 30, 2025

@vazhnov This library should be a thin wrapper, so I don't want to add a lot of extra methods for API functions that are a ready covered.

But I'm open to enhance the existing ChangesetsGet, but I would prefer a different approach: check if more records should be requested after each request. Similar to the DataLoader in one of my other projects.

@Claude Claude AI mentioned this pull request Feb 17, 2026
@metaodi
Copy link
Copy Markdown
Owner

metaodi commented Feb 17, 2026

PR in #188

@metaodi metaodi closed this Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants