My Wakeup Alarm

#!/usr/bin/env php
<?php
$dom=DOMDocument::load('http://weather.yahooapis.com/forecastrss?p=44047');
$items=$dom->getElementsByTagName('item');
foreach($items as $item) {
	foreach($item->childNodes as $child) {
		if ($child->namespaceURI=='http://xml.weather.yahoo.com/ns/rss/1.0') {
			if ($child->localName=='forecast') {
				$forecast="Today's forecast: ".$child->getAttribute('text')." with a high of ".$child->getAttribute('high');
				break 2;
			}
		}
	}
}
echo $forecast."\n";
?>

Pipe the output through festival --tty. In addition to running this script, the alarm crontab entry also starts up Amarok. Loudly. It sets it to stop playback at the end of the song, so I don’t have to fumble around with unlocking the desktop and then stopping the playback.

Automation is sweet.

Leave a Reply