Lupanoide
Lupanoide

Reputation: 3222

Get dateTime from weekday

I'm scraping data from a website and I would like to know when this data are updated. But on the site there is not an absolute data, only a reference like this: Updated on Monday 21:00 or this one, Update 1 day ago. Anyone can help me to get the timestamp from these strings? Thanks

Upvotes: 1

Views: 93

Answers (1)

jfs
jfs

Reputation: 414875

You could use parsedatetime module as @Tom Ron suggested:

#!/usr/bin/env python
import parsedatetime as ptd

ptc = ptd.Constants()
ptc.YearParseStyle = 0 # avoid future year
ptc.DOWParseStyle = 0 # how weekday is parsed
cal = ptd.Calendar(ptc)
for human_time in ["Updated on Monday 21:00", "1 day ago"]:
    print(cal.parseDT(human_time)[0])

Output

2015-11-30 21:00:00
2015-11-30 20:49:03

Upvotes: 1

Related Questions