aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiming Wang <zmwangx@gmail.com>2015-05-22 00:56:38 -0700
committerZhiming Wang <zmwangx@gmail.com>2015-05-22 00:56:38 -0700
commite43c335933be92a61d196a4c562e09e9fc85c3f3 (patch)
treef2095bc5fde2adab2f2d7c4d7bc5bd773c8f3377
parent2347cfeb381a49b5edee5151cb74cc3dae679040 (diff)
downloadmy_new_personal_website-e43c335933be92a61d196a4c562e09e9fc85c3f3.tar.xz
my_new_personal_website-e43c335933be92a61d196a4c562e09e9fc85c3f3.zip
pyblog: bug fix in auto retouch
-rwxr-xr-xpyblog18
1 files changed, 11 insertions, 7 deletions
diff --git a/pyblog b/pyblog
index cee67bee..eca043ff 100755
--- a/pyblog
+++ b/pyblog
@@ -2,6 +2,10 @@
"""A simple blog generator with Pandoc as backend."""
+# TODO: put blog configurations in a config file
+# TODO: auto retouch: prompt for git commit amend after touching
+# (display commit message to avoid amending the wrong commit)
+
import argparse
from contextlib import contextmanager
import datetime
@@ -26,8 +30,6 @@ import colorama
import dateutil.parser
import dateutil.tz
-# TODO: put blog configurations in a config file
-
############################# BLOG CONFIGURATIONS ##############################
# Safe to customize
BLOG_HOME = "http://zmwangx.github.io"
@@ -780,6 +782,7 @@ def gen_deploy(args):
# try to smartly determine the latest post, and prompt to touch it
current_time = time.time()
latest_post = None
+ latest_postdate = 0
latest_mtime = 0
for name in os.listdir(POSTSDIR):
matchobj = re.match(r"^([0-9]{4})-([0-9]{2})-([0-9]{2})-.*\.md", name)
@@ -788,25 +791,26 @@ def gen_deploy(args):
fullpath = os.path.join(POSTSDIR, name)
mtime = os.path.getmtime(fullpath)
# get post date from the date metadata field of the post
- postdate = datetime.datetime.fromtimestamp(0)
+ postdate = 0
with open(fullpath) as postobj:
for line in postobj:
- dateregex = r"^date: (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2})"
+ dateregex = r"^date: (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:?\d{2})"
datematch = re.match(dateregex, line.rstrip())
if datematch:
- postdate = dateutil.parser.parse(datematch.group(1))
+ postdate = dateutil.parser.parse(datematch.group(1)).timestamp()
break
# skip the post if it is dated more than three days ago
- if current_time - posttime > 3 * 24 * 3600:
+ if current_time - postdate > 3 * 24 * 3600:
continue
if mtime > latest_mtime:
latest_post = name
+ latest_postdate = postdate
latest_mtime = mtime
# prompt for touching if the latest post determined above was
# modified within the last hour but the date registered in the post
# isn't within the last ten minutes
if ((latest_post is not None and current_time - latest_mtime < 3600 and
- current_time - postdate > 60)):
+ current_time - latest_postdate > 600)):
sys.stderr.write("%sIt appears that %s might be a new post.\n"
"Do you want to touch its timestamp?%s\n" %
(GREEN, latest_post, RESET))