posted by [identity profile] wilhelmina-d.livejournal.com at 10:29am on 2003-10-13
First - I love this quote. Right on! :p
Second - how do you get your computer to post a quote every day without having to do it manually? I'd like to do the same, as I have a whole bunch of weight loss type quotes I'd like to add. Any help you could give would be appreciated! Thanks!
 
posted by [identity profile] dglenn.livejournal.com at 11:49pm on 2003-10-13

This might not be helpful to you, but my technique is this:



I have a file in my home directory called LJQUOTES and a subdirectory called quotetmp. The LJQUOTES file looks like this:

<!-- cut line for QotD automation script -- Tue 20031104 -->



<p><i>"Ignore your rights and they'll go away"</i> --

bumper sticker</i></p>



<!-- cut line for QotD automation script -- Wed 20031105 -->



<p><lj user="jducoeur">

<a href="http://www.livejournal.com/users/jducoeur/39456.html">

wrote</a>, <i>"The only reasonable conclusion is that

the universe is whimsical when bored..."</i></p>



<!-- cut line for QotD automation script -- Thu 20031106 -->



<p><i>"The answer may not end up in a major scientific journal or

dramatically change [...]



[. . .]



<!-- cut line for QotD automation script -- Sun 20040104 -->



<p>+++ If you see this, it means I screwed up and let my automatic

quote-of-the-day script run out of quotes to post.</p>



<!-- cut line for QotD automation script -- Mon 20040105 -->



<p>+++ If you see this, it means I screwed up and let my automatic

quote-of-the-day script run out of quotes to post.</p>



Then I've got a script called qotd:

# Move to directory just for dealing with quotes.

cd ~/quotetmp

# Break LJQUOTEFILE into individual entries for ease of manipulation.

csplit ../LJQUOTEFILE -n 4 '/cut line for QotD automation script/' "{*}"

# Strip off delimiter from the quote I'm going to post, then call the 
# 'clive' LJ client to post it and mail myself a copy.

sed -e "/cut line for QotD automation script/d" xx0001 > today.tmp
/shared/Software/Linux-386/clive -p -u dglenn -w LunaGrad -s QotD < today.tmp
mail -s "Automagically posted LJ QotD" `whoami` < today.tmp

# Clean up:  Delete the un-stripped copy of the entry 
# just posted, as well as the empty file 'csplit' will have 
# left as xx0000...

rm xx0001 xx0000

# Glue all the other entries back together as a new copy of 
# LJQUOTEFILE and delete the xx* files...

cat xx* > ../LJQUOTEFILE
rm xx*

# And give an archival filename to the edited entry just posted.

mv today.tmp qotd.`date +%Y%m%d`.html



And finally, in /var/spool/cron/dglenn, is the following line:


25 5 * * * /home/dglenn/bin/qotd | /usr/bin/tail -5

(The 'tail' at the end is so that just enough of the output to troubleshoot when things go wrong gets mailed to me each morning by the 'cron' daemon.)



If you're running Windows or MacOS 9.x or earlier (no clue here about BeOS) you'll have to do things a little differently or a lot differently, depending on what extra goodies you have or haven't installed. The same basic approach should work as long as there's a scheduling tool to take the place of 'cron' and something that'll chop the quotes file up and massage it apropriately. I haven't tried this under MacOS X yet, but I don't see why it wouldn't work as long as you can get 'clive' to compile (which shouldn't be hard).



There's probably a less-roundabout way do do it using Perl or Python, but it was quicker for me to hack it together using tools I didn't have to think about. I should really add error-checking so it'll automatically notice (and react to) problems such as my net connection being down or LJ being twitchy, but currently I just check it when I wake up and manually post any entry that didn't work automagically.



Dunno whether this helps or not ... I guess it depends on what tools you've got handy. I don't think I know what operating systems you use.

Links

January

SunMonTueWedThuFriSat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24
 
25
 
26
 
27
 
28
 
29
 
30
 
31