Skip to content

Instantly share code, notes, and snippets.

@tharmann
Last active May 11, 2017 15:57
Show Gist options
  • Save tharmann/116b93b3b07350c3a69193ac15819050 to your computer and use it in GitHub Desktop.
Save tharmann/116b93b3b07350c3a69193ac15819050 to your computer and use it in GitHub Desktop.
A little python script for notepad++. This searches through a WordPress xml export file and converts date strings to unix timestamps. Very useful when using wp-types for custom date fields. Requires the notepad++ python plugin..
import time
import datetime
editor.beginUndoAction()
def calculate(match):
epoch = datetime.datetime(1970, 1, 1)
s = "%s/%s/%s" % (match.group(1), match.group(2), match.group(3))
t = datetime.datetime.strptime(s, "%Y/%m/%d")
diff = t-epoch
i = int(diff.total_seconds())
utimes = str(i)
return '[' + utimes + ']'
editor.rereplace('\[([0-9]+)/+([0-9]+)/+([0-9]+)\]', calculate)
editor.endUndoAction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment