I finally managed to get a sound card for an old computer. Now, I can make my Ubuntu Alarm Clock! What better way to wake up each morning, than to have your friendly linux box read the news to you? The techniques that I am using are nothing new (Hak5 did it and some people at the Ubuntu Forums have talked about it). It is pretty simple, just download and install the rss2html.pl file and the necessary perl libaries, then create a bash script and add it to the crontab.
Get the programs
You will need festival and perl. You will also need mplayer if you want to play music. You can do the standard “sudo apt-get install …” to get these (they were all installed in my basic edgy installation).
I am going to use cpan to install the perl modules. cpan is like apt for perl. You might have to set up cpan if this is your first time using it. If you are asked to set it up, I recommend typing “no” on the first question, and cpan will autoconfigure.
At the terminal:
sudo cpan
This is the cpan terminal, autoconfigure if necessary. It may take a while to install each package. If it says it requires other modules, install them as well.
install XML::RSS install XML::Parser install DateTime::Format::Mail install DateTime::Format::W3CDTF
Create a file called “rss2html.pl” in ~/alarm and put this in it:
rss2html.pl
#!/usr/bin/perl -w # rss2html - converts an RSS file to HTML # It take one argument, either a file on the local system, # or an HTTP URL like http://slashdot.org/slashdot.rdf # by Jonathan Eisenzopf. v1.0 19990901 # Copyright (c) 1999 Jupitermedia Corp. All Rights Reserved. # See http://www.webreference.com/perl for more information # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # ~~~P1mped 0ut l33t hax0r s7yle by d1gital~~~ # INCLUDES use strict; use XML::RSS; use LWP::Simple; # Declare variables my $content; my $file; # MAIN # check for command-line argument die "Usage: rss2html.pl( | )\n” unless @ARGV == 2; # get the command-line argument my $arg = shift; my $lines = $arg; $arg = shift; # create new instance of XML::RSS my $rss = new XML::RSS; # argument is a URL if ($arg=~ /http:/i) { $content = get($arg); die “Could not retrieve $arg” unless $content; # parse the RSS content $rss->parse($content); # argument is a file } else { $file = $arg; die “File \”$file\” does’t exist.\n” unless -e $file; # parse the RSS file $rss->parsefile($file); } # print the HTML channel &print_html($rss); # SUBROUTINES sub print_html { my $rss = shift; print <{’items’}}) { next unless defined($item->{’title’}); print “$item->{’title’}… … … … …\n”; if($i==$lines - 1){ last; } $i = $i + 1; } print < Play a Random Song
You don’t have to do this, but I want to hear a song after the news, so make a file, music.sh in ~/alarm
From the Ubuntu Forummusic.sh
#!/bin/bash #made by rusl modifying file #from http://www.macosxhints.com/article.p...51108193636341 # File locations WritingsPath=/home// / TempLog=/tmp/random-alarm-music.log # Create a temporary logfile of all matches find $WritingsPath -iregex “.*.mp3″ > $TempLog find $WritingsPath -iregex “.*.ogg” >> $TempLog find $WritingsPath -iregex “.*.wav” >> $TempLog # Choose a random line number (any number from 1 to the length of the file) LowerBound=1 RandomMax=32767 UpperBound=$(cat $TempLog | wc -l) RandomLine=$(( $LowerBound + ($UpperBound * $RANDOM) / ($RandomMax + 1) )) # Use sed to grab the random line Command=$(sed -n “$RandomLine{p;q;}” “$TempLog”) # open the random line in TextEdit mplayer “$Command” Make Your Alarm File
Make a file alarm.sh in ~/alarm
alarm.sh
rm -rf alarm.txt echo "good morning , today is" >> alarm.txt date >> alarm.txt echo "From Digg" >> alarm.txt ~/alarm/rss2html.pl 6 http://digg.com/rss/index.xml >> alarm.txt echo "From Slashdot" >> alarm.txt ~/alarm/rss2html.pl 6 http://rss.slashdot.org/Slashdot/slashdot >> alarm.txt festival --tts alarm.txt rm -rf alarm.txt ~/alarm/music.shYou can add any number of news sources.
Set Permissions
cd ~/alarm
chmod +x rss2html.pl
chmod +x alarm.shSet Your Alarm
Use the crontab to set your alarm. From the terminal:
crontab -eAnd paste this into the file:
0 7 * * * /home/USERNAME/alarm/alarm.shFurther additions
- Hak5 has a script to get the weather.

March 25th, 2007 at 8:09 pm
This is a pretty neat idea. I am going to have to try this. I would like to wake up to the news that I want to hear, not that “news” they play on the TV in the morning, lol.
August 7th, 2007 at 8:31 am
Hey, this sounds pretty awesome. Is there any way you could put all this into a spiffy little easy to use GUI and get it in the repos for Gutsy? I for one have not found a great alarm clock app yet for Linux OR Windows. Thanks in advance! Oh, and if you DO put together a reasonable GUI for it, I’ll host the site and put up a web page and submit news and etc…..
November 8th, 2007 at 11:46 am
[...] read more | digg story [...]
April 26th, 2008 at 4:37 am
Sécurité : Porte blindée ou alarme ?…
Avant de prendre une décision finale sur une porte blindée ou une signalisation, pesez le pour et le contre, parce que les portes blindées ont aussi leurs défauts……