From 629ea59c284c566bef0faa547b1fc041c3c7445f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 20 Dec 2025 16:45:44 +0000 Subject: [PATCH] Tidying --- newswire.py | 15 +++------------ timeFunctions.py | 1 + 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/newswire.py b/newswire.py index c25cb7892..4afc2d7df 100644 --- a/newswire.py +++ b/newswire.py @@ -12,7 +12,6 @@ import json import requests import random import time -import datetime from socket import error as SocketError import errno from datetime import timedelta @@ -320,7 +319,6 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str: "%Y-%m-%dT%H:%M:%S%Z", "%a, %d %b %Y %H:%M:%S") published_date = None - errmsg = '' timezone_endings = ( ',', 'Z', 'GMT', 'EST', 'PST', 'AST', 'CST', 'MST', 'AKST', 'HST', 'UT' @@ -353,18 +351,11 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str: try: published_date = \ - datetime.datetime.strptime(pub_date2, date_format) - # published_date = \ - # date_from_string_format(pub_date2, [date_format]) - except BaseException as exc: - errmsg = ' | ' + date_format + ' ' + \ - str(exc).replace('\n', ' ').replace('\r', ' ') + date_from_string_format(pub_date2, [date_format]) + except BaseException: continue if published_date is not None: - if not published_date.tzinfo: - published_date = \ - published_date.replace(tzinfo=timezone.utc) if pub_date.endswith(' EST'): hours_added = timedelta(hours=5) published_date = published_date + hours_added @@ -381,7 +372,7 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str: if not pub_date_str.endswith('+00:00'): pub_date_str += '+00:00' else: - print('WARN: unrecognized date format: ' + pub_date + errmsg) + print('WARN: unrecognized date format: ' + pub_date) return pub_date_str diff --git a/timeFunctions.py b/timeFunctions.py index 19fc8c792..232d6c063 100644 --- a/timeFunctions.py +++ b/timeFunctions.py @@ -72,6 +72,7 @@ def date_from_string_format(date_str: str, formats: []): "%a, %d %b %Y %H:%M:%S %z", "%Y-%m-%dT%H:%M:%S%z") dtime = None + date_str = date_str.strip() for date_format in formats: try: dtime = \