mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 14:44:29 -04:00
use dateparser for parsing, let it handle error
This commit is contained in:
parent
58ac44c867
commit
b7785c4138
3 changed files with 7 additions and 6 deletions
|
@ -190,10 +190,10 @@ class Link:
|
||||||
for key, val in json_info.items()
|
for key, val in json_info.items()
|
||||||
if key in cls.field_names()
|
if key in cls.field_names()
|
||||||
}
|
}
|
||||||
try:
|
# try:
|
||||||
info['updated'] = int(parse_date(info.get('updated'))) # Cast to int which comes with rounding down
|
info['updated'] = parse_date(info.get('updated')) # Cast to int which comes with rounding down
|
||||||
except (ValueError, TypeError):
|
# except (ValueError, TypeError):
|
||||||
info['updated'] = None
|
# info['updated'] = None
|
||||||
info['sources'] = info.get('sources') or []
|
info['sources'] = info.get('sources') or []
|
||||||
|
|
||||||
json_history = info.get('history') or {}
|
json_history = info.get('history') or {}
|
||||||
|
|
|
@ -9,7 +9,7 @@ from hashlib import sha256
|
||||||
from urllib.parse import urlparse, quote, unquote
|
from urllib.parse import urlparse, quote, unquote
|
||||||
from html import escape, unescape
|
from html import escape, unescape
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dateutil import parser as dateparser
|
from dateparser import parse as dateparser
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from base32_crockford import encode as base32_encode # type: ignore
|
from base32_crockford import encode as base32_encode # type: ignore
|
||||||
|
@ -144,7 +144,7 @@ def parse_date(date: Any) -> Optional[datetime]:
|
||||||
date = str(date)
|
date = str(date)
|
||||||
|
|
||||||
if isinstance(date, str):
|
if isinstance(date, str):
|
||||||
return dateparser.parse(date)
|
return dateparser(date)
|
||||||
|
|
||||||
raise ValueError('Tried to parse invalid date! {}'.format(date))
|
raise ValueError('Tried to parse invalid date! {}'.format(date))
|
||||||
|
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -43,6 +43,7 @@ setuptools.setup(
|
||||||
"django==3.0.7",
|
"django==3.0.7",
|
||||||
"django-extensions==2.2.9",
|
"django-extensions==2.2.9",
|
||||||
|
|
||||||
|
"dateparser",
|
||||||
"ipython",
|
"ipython",
|
||||||
"youtube-dl",
|
"youtube-dl",
|
||||||
"python-crontab==2.5.1",
|
"python-crontab==2.5.1",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue