upgrade scraping and searching
This commit is contained in:
32
html_scrapy/guess_date.py
Normal file
32
html_scrapy/guess_date.py
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
from datetime import datetime
|
||||
from dateutil.parser import parse
|
||||
import locale
|
||||
from contextlib import suppress
|
||||
|
||||
def parse(s):
|
||||
with suppress(BaseException):
|
||||
date_format = '%H:%M, %d. %b. %Y'
|
||||
locale.setlocale(locale.LC_TIME, 'en_US')
|
||||
parsed_date = datetime.strptime(s, date_format)
|
||||
return parsed_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
|
||||
with suppress(BaseException):
|
||||
date_format = '%H:%M, %d. %b. %Y'
|
||||
locale.setlocale(locale.LC_TIME, 'de_DE')
|
||||
parsed_date = datetime.strptime(s, date_format)
|
||||
return parsed_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
|
||||
with suppress(BaseException):
|
||||
date_format = '%H:%M, %d. %B %Y'
|
||||
locale.setlocale(locale.LC_TIME, 'de_DE')
|
||||
parsed_date = datetime.strptime(s, date_format)
|
||||
return parsed_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
|
||||
with suppress(BaseException):
|
||||
locale.setlocale(locale.LC_TIME, 'de_DE')
|
||||
parsed_date = parse(s, dayfirst=True)
|
||||
return parsed_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
|
||||
|
||||
return s
|
||||
Reference in New Issue
Block a user