Last active
May 11, 2017 15:57
-
-
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..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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