From f304f57eeb9e1b375629459459b2145df41b5cf3 Mon Sep 17 00:00:00 2001 From: Jocelyn Jaubert Date: Mon, 26 Oct 2026 22:45:35 +0100 Subject: [PATCH] tools: Add option --user-agent User-agent is then replaced by "pyosmium/{version} - VALUE". --- src/osmium/tools/pyosmium_get_changes.py | 7 +++++++ src/osmium/tools/pyosmium_up_to_date.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/osmium/tools/pyosmium_get_changes.py b/src/osmium/tools/pyosmium_get_changes.py index b837f9b..8528c68 100644 --- a/src/osmium/tools/pyosmium_get_changes.py +++ b/src/osmium/tools/pyosmium_get_changes.py @@ -108,6 +108,8 @@ def get_arg_parser(from_main: bool = False) -> ArgumentParser: help='Do not deduplicate diffs.') parser.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60, help='Set timeout for file downloads.') + parser.add_argument('--user-agent', dest='user_agent', + help='Append given user-agent to default user-agent') parser.add_argument('--version', action='version', version='pyosmium ' + pyosmium_release) return parser @@ -163,6 +165,11 @@ def pyosmium_get_changes(args: List[str]) -> int: cookie_jar.load(options.cookie) svr.set_request_parameter('cookies', cookie_jar) + if options.user_agent is not None: + svr.set_request_parameter('headers', + {'User-Agent': + f"pyosmium/{pyosmium_release} - {options.user_agent}"}) + # Sanity check if server URL is correct and server is responding. current = svr.get_state_info() if current is None: diff --git a/src/osmium/tools/pyosmium_up_to_date.py b/src/osmium/tools/pyosmium_up_to_date.py index ec0c8ca..97c5043 100644 --- a/src/osmium/tools/pyosmium_up_to_date.py +++ b/src/osmium/tools/pyosmium_up_to_date.py @@ -79,6 +79,11 @@ def update_from_custom_server(start: ReplicationStart, options: Any) -> int: cookie_jar.load(options.cookie) svr.set_request_parameter('cookies', cookie_jar) + if options.user_agent is not None: + svr.set_request_parameter('headers', + {'User-Agent': + f"pyosmium/{pyosmium_release} - {options.user_agent}"}) + current = svr.get_state_info() if current is None: log.error("Cannot download state information. Is the replication URL correct?") @@ -238,6 +243,8 @@ def get_arg_parser(from_main: bool = False) -> ArgumentParser: 'received cookies will be written to.') parser.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60, help='Set timeout for file downloads.') + parser.add_argument('--user-agent', dest='user_agent', + help='Append given user-agent to default user-agent') parser.add_argument('--version', action='version', version='pyosmium ' + pyosmium_release)