Skip to content

Instantly share code, notes, and snippets.

@ysangkok
Created May 3, 2016 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysangkok/3ec45549530ce2ee991ba43a4f4ae16c to your computer and use it in GitHub Desktop.
Save ysangkok/3ec45549530ce2ee991ba43a4f4ae16c to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
define("type","BBC");
#define("type","DMI");
//define("PLACE",35); //copenhagen
define("PLACE",52); //frankfurt
ob_start();
if (type == "DMI") {
$str_xml = file_get_contents("http://www.dmi.dk/eng/denmark_forecast.rss");
} elseif (type == "BBC") {
$str_xml = file_get_contents("http://newsrss.bbc.co.uk/weather/forecast/" . PLACE . "/Next3DaysRSS.xml");
}
$xml = new SimpleXMLElement($str_xml);
if (type != "DMI") echo $xml->channel->title . "\n";
foreach($xml->channel->item as $item) {
echo $item->title . "\n";
if (type != "BBC") echo $item->description . "\n";
}
$contents = ob_get_contents();
ob_end_clean();
$newcon = array();
foreach (explode("\n",$contents) as $line) {
if (type == "BBC") {
$line = str_replace("°C", " degrees Celcius" ,$line);
$line = str_replace("°F", " degrees Fahrenheit",$line);
$line = str_replace("Min", "Minimum", $line);
$line = str_replace("Max", "Maximum", $line);
$line = str_replace("Temp","temperature", $line);
$line = str_replace("," ,";", $line);
$line = trim(shell_exec("echo " . escapeshellarg($line) . " | sed -re 's/\(.*\)//'"));
}
if ($line != "") $newcon[] = trim($line) . ".";
}
$contents = implode("\n",$newcon);
echo $contents;
$b = "";
for ($i=0; $i<strlen($contents); $i++) {
$b .= "\\0" . sprintf("%03d",decoct(ord($contents[$i])));
}
shell_exec("echo -ne " . escapeshellarg($b) . " | aoss ~janus/festival/bin/festival --tts");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment