Skip to content

Instantly share code, notes, and snippets.

@jpfinley
Created October 17, 2010 20:10
Show Gist options
  • Save jpfinley/631225 to your computer and use it in GitHub Desktop.
Save jpfinley/631225 to your computer and use it in GitHub Desktop.
Enter in your zip code, and it tells you if an umbrella is necessary.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/twilio/finley/umbrella.php" method="GET">
<Say>Please enter your zip code, followed by the pound sign.</Say>
</Gather>
<Say>We didn't receive any input. Call back another time!</Say>
</Response>
<?php
$reader = new XMLReader();
$reader->open('http://weather.yahooapis.com/forecastrss?p=' . $_REQUEST['Digits']);
while ($reader->read()) {
if($reader->name == "yweather:location"){
$location = $reader->getAttribute("city");
}
if($reader->name == "yweather:condition"){
$condition = $reader->getAttribute("text");
}
}
$reader->close();
// http://developer.yahoo.com/weather/#codes
if($condition == "rain"
|| $condition == "hurricane"
|| $condition == "tornado"
|| $condition == "showers"
|| $condition == "thunderstorms"
|| $condition == "drizzle"
|| $condition == "hail"
|| $condition == "mixed rain and sleet"
|| $condition == "scattered showers"){
$recommendation = "So you should bring your umbrella.";
}
else{
$recommendation = "So you should leave your umbrella at home.";
}
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>If you are going to be in or around <?php echo $location ?>...</Say>
<Say>It will be <?php echo $condition ?> today...</Say>
<Say><?php echo $recommendation ?></Say>
</Response>
@jpfinley
Copy link
Author

Absolutely right; once those descriptions change, this is toast.

I just threw this together as a prototype for class. We are fooling around with twilio and I wanted to see how I might use it to replicate Umbrella Today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment