From f6e5ec8c75b434b74d9e2ed2abdb36e92f7255a1 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 28 Aug 2025 07:38:47 +0200 Subject: fix: only log connection errors as errors if last success was a day ago --- osm_proposals/proposals.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/osm_proposals/proposals.py b/osm_proposals/proposals.py index 5431e96..fff8c51 100755 --- a/osm_proposals/proposals.py +++ b/osm_proposals/proposals.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 """Queries wiki.openstreetmap.org for proposals and writes a JSON list of them to the given file.""" import argparse +import datetime import html import json import sys @@ -29,7 +30,30 @@ def run(): arg_parser.add_argument("out_file") args = arg_parser.parse_args() - proposals = find_proposals() + try: + proposals = find_proposals() + except requests.exceptions.ConnectionError: + # For some reason the OSM wiki gives connection errors on average one per day (with this running hourly). + # Some days none, some days several. + + with open(args.out_file, 'r') as f: + last_updated = datetime.datetime.fromtimestamp(json.load(f)["last_updated"]) + + age = datetime.datetime.now() - last_updated + + if age > datetime.timedelta(days=1): + logger.error( + f"connection error escalated because last successful update was {age} ago", + traceback=True, + data_age=age.total_seconds(), + ) + else: + logger.info( + f"connection error deemed ok because last successful update was {age} ago", + traceback=True, + data_age=age.total_seconds(), + ) + return with open(args.out_file, 'w') as f: json.dump({"last_updated": int(time.time()), "proposals": proposals}, f) -- cgit v1.2.3