main
Bob Mottram 2025-12-20 14:55:08 +00:00
parent bf82b867b1
commit 3423c6bb24
1 changed files with 7 additions and 7 deletions

View File

@ -275,8 +275,8 @@ def _add_newswire_dict_entry(base_dir: str,
def _valid_feed_date(pub_date: str, debug: bool = False) -> bool: def _valid_feed_date(pub_date: str, debug: bool = False) -> bool:
# convert from YY-MM-DD HH:MM:SS+00:00 to """ convert from YY-MM-DD HH:MM:SS+00:00 to YY-MM-DDTHH:MM:SSZ
# YY-MM-DDTHH:MM:SSZ """
post_date = pub_date.replace(' ', 'T').replace('+00:00', 'Z') post_date = pub_date.replace(' ', 'T').replace('+00:00', 'Z')
if '.' in post_date: if '.' in post_date:
ending = post_date.split('.')[1] ending = post_date.split('.')[1]
@ -321,6 +321,7 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str:
published_date = None published_date = None
errmsg = '' errmsg = ''
for date_format in formats: for date_format in formats:
errmsg += ' | ' + date_format
if ',' in pub_date and ',' not in date_format: if ',' in pub_date and ',' not in date_format:
continue continue
if ',' not in pub_date and ',' in date_format: if ',' not in pub_date and ',' in date_format:
@ -350,22 +351,21 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str:
elif '-' in ending: elif '-' in ending:
timezone_str = '-' + ending.split('-')[1] timezone_str = '-' + ending.split('-')[1]
pub_date2 = pub_date2.split('.')[0] + timezone_str pub_date2 = pub_date2.split('.')[0] + timezone_str
errmsg += ' ' + pub_date2
try: try:
published_date = date_from_string_format(pub_date2, [date_format]) published_date = date_from_string_format(pub_date2, [date_format])
except BaseException as exc: except BaseException:
if date_format == "%a, %d %b %Y %H:%M:%S":
errmsg = '| ' + pub_date2 + '| ' + str(exc)
continue continue
if published_date: if published_date is not None:
if pub_date.endswith(' EST'): if pub_date.endswith(' EST'):
hours_added = timedelta(hours=5) hours_added = timedelta(hours=5)
published_date = published_date + hours_added published_date = published_date + hours_added
break break
pub_date_str = None pub_date_str = None
if published_date: if published_date is not None:
offset = published_date.utcoffset() offset = published_date.utcoffset()
if offset: if offset:
published_date = published_date - offset published_date = published_date - offset