0
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

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
hinata
  • 45
  • 1
  • 9

1 Answers1

0

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']
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563