Yahoo! Weather|Kirsle|casey@cuvou.net|1241119060|Kirsle|xx|0|72.37.252.50|This will enable your Perl RS bot to look up weather conditions and forecasts for its users (currently only supports US zip codes):<br /><br />[code]/* Yahoo! Weather for RiveScript<br />  Retrieve weather conditions and forecast from Yahoo! Weather.<br />  Usage: weather &lt;zipcode&gt;<br />   or: how is the weather?<br /><br />  Author: Casey Kirsle, www.kirsle.net<br /><br />  Perl Dependencies:<br />   LWP::Simple (to retrieve Yahoo Weather)<br />   XML::Simple (to parse the XML data)<br /><br />  RiveScript Dependencies:<br />   ! sub don't = do not<br />*/<br />! version = 2.0<br /><br />+ weather #&#123;weight=100&#125;<br />- &lt;call&gt;weather &lt;star&gt;&lt;/call&gt;<br /><br />+ what is the weather<br />* &lt;get zipcode&gt; != undefined =&gt; &#123;@weather &lt;get zipcode&gt;&#125;<br />- I can tell you how the weather is, but I don't know your zip code. What is it?<br /><br />+ #<br />% * i do not know your zip code what is it<br />* &lt;call&gt;validzip &lt;star&gt;&lt;/call&gt; == 1 =&gt; &lt;set zipcode=&lt;star&gt;&gt;Okay, I will remember that your zip code is &lt;star&gt;.\n\n&#123;@weather &lt;star&gt;&#125;<br />- That isn't a valid zip code. You should've answered as a number, like &quot;90230&quot;.<br /><br />+ how is the weather<br />@ what is the weather<br /><br />+ what is the weather like<br />@ what is the weather<br /><br />+ do you know [how] the weather [is]<br />@ what is the weather<br /><br />+ how (warm&#124;hot&#124;cold) is it [outside]<br />@ what is the weather<br /><br />+ weather&#123;weight=100&#125;<br />@ what is the weather<br /><br />+ what is the weather [like] in #<br />@ weather &lt;star&gt;<br /><br />+ how is the weather in #<br />@ weather &lt;star&gt;<br /><br />+ do you know [how] the weather is in #<br />@ weather &lt;star&gt;<br /><br />+ how (warm&#124;hot&#124;cold) is it in #<br />@ weather &lt;star&gt;<br /><br />+ my zip code is #&#123;weight=100&#125;<br />* &lt;call&gt;validzip &lt;star&gt;&lt;/call&gt; == 1 =&gt; &lt;set zipcode=&lt;star&gt;&gt;I will remember that your zip code is &lt;star&gt;.<br />- That zip code doesn't seem to be valid. It should be 5 numbers.<br /><br />+ my zip is #&#123;weight=100&#125;<br />@ my zip code is &lt;star&gt;<br /><br />+ my zipcode is #&#123;weight=100&#125;<br />@ my zip code is &lt;star&gt;<br /><br />&gt; object validzip perl<br />  my ($rs,$zip) = (shift,shift);<br /><br />  if (length $zip == 5) &#123;<br />   return 1;<br />  &#125;<br />  else &#123;<br />   return 0;<br />  &#125;<br />&lt; object<br /><br />&gt; object weather perl<br />  my ($rs,$zip) = (shift,shift);<br /><br />  if (length $zip != 5) &#123;<br />   return &quot;That isn't a valid zip code!&quot;;<br />  &#125;<br /><br />  use LWP::Simple;<br />  use XML::Simple;<br /><br />  my $o_xs = new XML::Simple;<br /><br />  my $rss = get &quot;http://weather.yahooapis.com/forecastrss?p=$zip&quot;;<br />  my $xml = XMLin($rss);<br /><br />  if (exists $xml-&gt;&#123;channel&#125;) &#123;<br />   my $channel = $xml-&gt;&#123;channel&#125;-&gt;&#123;item&#125;;<br />   my $temp = $channel-&gt;&#123;'yweather:condition'&#125;-&gt;&#123;temp&#125;;<br />   my $condition = $channel-&gt;&#123;'yweather:condition'&#125;-&gt;&#123;text&#125;;<br /><br />   my $city = $xml-&gt;&#123;channel&#125;-&gt;&#123;'yweather:location'&#125;-&gt;&#123;city&#125;;<br />   my $state = $xml-&gt;&#123;channel&#125;-&gt;&#123;'yweather:location'&#125;-&gt;&#123;region&#125;;<br />   my $wind = $xml-&gt;&#123;channel&#125;-&gt;&#123;'yweather:wind'&#125;-&gt;&#123;speed&#125;;<br />   my $tomorrow = $channel-&gt;&#123;'yweather:forecast'&#125;-&gt;[0];<br />   my $nextday = $channel-&gt;&#123;'yweather:forecast'&#125;-&gt;[1];<br /><br />   my $tip = &quot;&quot;;<br />   if (int(rand(3)) == 0) &#123;<br />     $tip = &quot;\n\nTip: I can tell you the weather for somewhere else &quot;<br />      . &quot;if you say e.g. \&quot;how is the weather in 48433\&quot;. If I know &quot;<br />      . &quot;your zip code and you want me to remember something else, &quot;<br />      . &quot;say e.g. \&quot;my zip code is 90230\&quot;.&quot;;<br />   &#125;<br /><br />   return &quot;Current Weather conditions for &lt;b&gt;$city, $state $zip&lt;/b&gt;:\n\n&quot;<br />     . &quot;&lt;b&gt;Current Conditions:&lt;/b&gt;\n&quot;<br />     . &quot;$condition, $temp F\n\n&quot;<br />     . &quot;&lt;b&gt;Forecast:&lt;/b&gt;\n&quot;<br />     . &quot;$tomorrow-&gt;&#123;day&#125; - $tomorrow-&gt;&#123;text&#125;. High: $tomorrow-&gt;&#123;high&#125;; Low: $tomorrow-&gt;&#123;low&#125;\n&quot;<br />     . &quot;$nextday-&gt;&#123;day&#125; - $nextday-&gt;&#123;text&#125;. High: $nextday-&gt;&#123;high&#125;; Low: $nextday-&gt;&#123;low&#125;$tip&quot;;<br />  &#125;<br />  else &#123;<br />   return &quot;There was an error retrieving the weather.&quot;;<br />  &#125;<br />&lt; object[/code]||1241119083|Kirsle|weather.rs
