Now on ScienceBlogs: HeartlandGate: Anti-Science Institute's Insider Reveals Secrets

ScienceBlogs Book Club: Inside the Outbreaks

Greg Laden's Blog

Evolution, Life Sciences, Science Education, Human Evolution, and Stuff

Darwing_Face.jpg Learn more about Charles Darwin and his work.

Hornbill170.jpg Looking for stuff about birds?

Lion_mane170.jpg Lean more about lions

Congo_sidebar.jpg An archaeological expedition to the Congo


The Skeptical Search Engine


Nature Blog Network
Climate Defense Fund


The contents of Greg Laden's Blog are copyrighted by Greg Laden.

Recent Comments

Search

Profile


Click on "About" for the big picture, and "Archives" for the details.


Recent Posts

Blogroll

If you don't see yourself on my blogroll, just drop me a line and let me know. I'll add you.*
*Assuming that I'm on your blogroll, of course!

Archives

« Heath News | Main | Space, the Final (political) Frontier... »

Movable Type Bloggers: A Neat Tip

Posted on: February 26, 2008 1:16 PM, by Greg Laden

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....

Share on Facebook
Share on StumbleUpon
Share on Facebook
Find more posts in: Technology

TrackBacks

TrackBack URL for this entry: http://scienceblogs.com/mt/pings/65123

Comments

1

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....

Posted by: blf | February 26, 2008 2:13 PM

2

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

Posted by: Greg Laden | February 26, 2008 2:18 PM

3

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.)

Posted by: rpenner | February 26, 2008 3:26 PM

4

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.

Posted by: rpenner | February 26, 2008 5:01 PM

Post a Comment

(Email is required for authentication purposes only. On some blogs, comments are moderated for spam, so your comment may not appear immediately.)





ScienceBlogs

Search ScienceBlogs:

Go to:

Advertisement
Follow ScienceBlogs on Twitter

© 2006-2011 ScienceBlogs LLC. ScienceBlogs is a registered trademark of ScienceBlogs LLC. All rights reserved.