Movable Type Bloggers: A Neat Tip

This is for Linux users, but there are ways to implement it on Windows and Mac boxes (but you are on your own.)

If you use the movable type interface, you will know that when you generate a “Create New Entry” page, the current date is placed in the “Entry Date” filed. But, as time passes, that date does not change. So, if you work on this post for an hour, the date of your post is now an hour stale. You get the point.

To fix this, you need to adjust the date before you “Publish” the post. But the date has to be in exactly the same format. And the time zone you are publishing on may not be the time zone you live in. And so on.

I have a solution.

I have a little script that you can have. I have a terminal window open, and when I type in “now” (the name of the executable script), I get a string of numbers that is the exact format Movable type requires, in EST (I live in CST). I can copy and paste this into the Entry Date field.

You may need to adjust the script to have your own time zone adjustment (or no adjustment at all). It should be obvious how to do this.

Put the script in a text file in your “bin” directory (which in turn should be on your PATH) and chmod it to make it executable.

Here is the script:

#/bin/bash
#
# outputs a date in MT format one hour from now (thus EST)
#
# REVISE LATER: Zap this output into the clipboard
#

date -d '+1 hour' '+%Y-%m-%d %H:%M:%S'

And here is what it looks like when it runs:

greg@greg-desktop:~$ now
2008-02-26 08:19:08

In the near future, I’ll revise this to make it more useful, but let me tell you what that will involve in case you want to start working on this now. I’ll pipe the output of this script to a python or perl app that will insert it onto the clipboard. Then, I’ll make a button on my Gnome task bar that runs the script. So, all I’ll need to get the current date is to hit the button and the date in on the clipboard ready to be pasted.

The next step after that, of course, is to have a bit of perl code that finds the web page and sticks the data into the appropriate field. I have no idea how to do this, but how hard can it be?

Then, the next obvious step is to run this script with the use of my new Mind Control Helmet.

Comments

  1. #1 blf
    February 26, 2008

    Zap this output into …

    Ah! Someone else who still(?) uses “zap” and (I presume) “crunch” for I/O redirections. Haven’t seen or heard that terminology in ages….

  2. #2 Greg Laden
    February 26, 2008

    Well, these are important technical terms to know. One must keep track to not accidentally clobber a file.

  3. #3 rpenner
    February 26, 2008

    Your example depends on the Linux/GNU date binary. People on older UNIX systems would have to use the following:
    TZ=EST5EDT '+%Y-%m-%d %H:%M:%S'

    But if you have access to Perl, you can likely use:
    #!/usr/bin/perl
    use strict;
    use warnings;
    use POSIX qw(strftime);
    print strftime(q(%Y-%m-%d %H:%M:%S), localtime(time()+3600)), "\n";

    or
    perl -MPOSIX=strftime -e "print strftime(q(%Y-%m-%d %H:%M:%S), localtime(time+3600)), qq(\n);"
    (Tested under cygwin, Active State perl (Windows XP), and Solaris.)

  4. #4 rpenner
    February 26, 2008

    In Python, the way you do this is very similar to Perl.

    >>> from time import strftime, localtime, time
    >>> print strftime("%Y-%m-%d %H:%M:%S", localtime(time()+3600)) + "\n"

    In C, which Python and Perl closely follow, here is a program which works on cygwin. (Your milage may vary.)


    #include
    #include
    #include

    #define BUFSIZE 80

    int main(int argc, char *argv[]) {
    time_t the_time;
    struct tm exploded_time;
    struct tm * result_ptr;
    size_t width;
    char * format = "%Y-%m-%d %H:%M:%S" ;
    char buffer[BUFSIZE];
    int status;

    the_time = time((time_t *) 0);
    if (the_time == (time_t) -1 ) {
    perror("time: error return status");
    exit(1);
    }
    the_time += 3600;
    result_ptr = localtime_r(&the_time, &exploded_time);
    if ( ! result_ptr ) {
    perror("localtime: error return status");
    exit(2);
    }
    width = strftime(buffer, (size_t) BUFSIZE, format, result_ptr);
    if ( width == 0 ) {
    fprintf(stderr, "strftime: format string results in date longer than %d characters", BUFSIZE);
    exit(3);
    }
    status = printf("%s\n", buffer);
    if ( ! status ) {
    perror("printf: failed");
    exit(4);
    }
    exit(0);
    }

    Now, that is why Python and Perl exist.

Current ye@r *