Created
October 17, 2010 20:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.