matches = list(datefinder.find_dates(str(laslogsystime[0])))
if len(matches) > 0:
date = matches[0]
# print(date)
logging = re.findall(r'(.*?)', date)[0]
print(logging)
TypeError: expected string or bytes-like object
matches = list(datefinder.find_dates(str(laslogsystime[0])))
if len(matches) > 0:
date = matches[0]
# print(date)
logging = re.findall(r'(.*?)', date)[0]
print(logging)
TypeError: expected string or bytes-like object
You must be trying to extract the strings that datefinder
identifies as datetime strings.
You need no re.findall
, you need to tell find_dates
to return tuples containing both datetime and source strings by passing source=True
argument:
import datefinder
from datetime import datetime
laslogsystime = "August 1990 some text May 21 2015"
matches = [src for time, src in datefinder.find_dates(laslogsystime, source=True)]
print(matches) # => ['August 1990', 'May 21 2015']