handle dd/mm/yyyy and yyyy-mm-dd dates in text

pull/977/head
Ben Parsons 7 years ago
parent 3b84de383c
commit 3b4e56c4e0

@ -74,6 +74,18 @@ for label in labels:
created = re.search('^Date: (.+?)\n', str(item['body']), flags=re.MULTILINE) created = re.search('^Date: (.+?)\n', str(item['body']), flags=re.MULTILINE)
if created is not None: if created is not None:
created = created.group(1).strip() created = created.group(1).strip()
try:
created = datetime.strptime(created, "%d/%m/%Y")
created = created.strftime('%Y-%m-%d')
except:
pass
try:
created = datetime.strptime(created, "%Y-%m-%d")
created = created.strftime('%Y-%m-%d')
except:
pass
else : else :
created = datetime.strptime(item['created_at'], "%Y-%m-%dT%XZ") created = datetime.strptime(item['created_at'], "%Y-%m-%dT%XZ")
created = created.strftime('%Y-%m-%d') created = created.strftime('%Y-%m-%d')

Loading…
Cancel
Save