Skip to content

Instantly share code, notes, and snippets.

@abevieiramota
Created April 21, 2018 01:24
Show Gist options
  • Save abevieiramota/2dba2d7174accdcf4196818386ba7fc4 to your computer and use it in GitHub Desktop.
Save abevieiramota/2dba2d7174accdcf4196818386ba7fc4 to your computer and use it in GitHub Desktop.
import re
import datetime
import codecs
c = re.compile('\d{1,4}-\d{1,2}-\d{1,2}')
with codecs.open('persondata_wkd_uris_pt.ttl', 'r', 'utf-8') as f_in, codecs.open('persondata_wkd_uris_pt.ttl.out', 'w', 'utf-8') as f_out:
for i, line in enumerate(f_in):
m = c.search(line)
if m:
str_date = m.group()
try:
d = datetime.datetime.strptime(str_date, '%Y-%m-%d')
str_date_out = d.strftime('%Y-%m-%d')
line = line.replace(str_date, str_date_out)
f_out.write(line)
except:
print("[{i}] : {date}".format(i=i, date=str_date))
else:
f_out.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment