mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
673122e90d
commit
629ea59c28
15
newswire.py
15
newswire.py
|
|
@ -12,7 +12,6 @@ import json
|
||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
import datetime
|
|
||||||
from socket import error as SocketError
|
from socket import error as SocketError
|
||||||
import errno
|
import errno
|
||||||
from datetime import timedelta
|
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",
|
"%Y-%m-%dT%H:%M:%S%Z",
|
||||||
"%a, %d %b %Y %H:%M:%S")
|
"%a, %d %b %Y %H:%M:%S")
|
||||||
published_date = None
|
published_date = None
|
||||||
errmsg = ''
|
|
||||||
timezone_endings = (
|
timezone_endings = (
|
||||||
',', 'Z', 'GMT', 'EST', 'PST', 'AST', 'CST', 'MST', 'AKST', 'HST',
|
',', 'Z', 'GMT', 'EST', 'PST', 'AST', 'CST', 'MST', 'AKST', 'HST',
|
||||||
'UT'
|
'UT'
|
||||||
|
|
@ -353,18 +351,11 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
published_date = \
|
published_date = \
|
||||||
datetime.datetime.strptime(pub_date2, date_format)
|
date_from_string_format(pub_date2, [date_format])
|
||||||
# published_date = \
|
except BaseException:
|
||||||
# date_from_string_format(pub_date2, [date_format])
|
|
||||||
except BaseException as exc:
|
|
||||||
errmsg = ' | ' + date_format + ' ' + \
|
|
||||||
str(exc).replace('\n', ' ').replace('\r', ' ')
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if published_date is not None:
|
if published_date is not None:
|
||||||
if not published_date.tzinfo:
|
|
||||||
published_date = \
|
|
||||||
published_date.replace(tzinfo=timezone.utc)
|
|
||||||
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
|
||||||
|
|
@ -381,7 +372,7 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str:
|
||||||
if not pub_date_str.endswith('+00:00'):
|
if not pub_date_str.endswith('+00:00'):
|
||||||
pub_date_str += '+00:00'
|
pub_date_str += '+00:00'
|
||||||
else:
|
else:
|
||||||
print('WARN: unrecognized date format: ' + pub_date + errmsg)
|
print('WARN: unrecognized date format: ' + pub_date)
|
||||||
|
|
||||||
return pub_date_str
|
return pub_date_str
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ def date_from_string_format(date_str: str, formats: []):
|
||||||
"%a, %d %b %Y %H:%M:%S %z",
|
"%a, %d %b %Y %H:%M:%S %z",
|
||||||
"%Y-%m-%dT%H:%M:%S%z")
|
"%Y-%m-%dT%H:%M:%S%z")
|
||||||
dtime = None
|
dtime = None
|
||||||
|
date_str = date_str.strip()
|
||||||
for date_format in formats:
|
for date_format in formats:
|
||||||
try:
|
try:
|
||||||
dtime = \
|
dtime = \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue