Jump to content

Archived

This topic is now archived and is closed to further replies.

chain

Weather script for mIRC

Recommended Posts

  • Administrators

Weather script for mIRC

 

Weather Bot Script. Does !WEATHER - !FORECASTS - !ALERTS - !TIME - WorldWide coverage.

 

I built a Weather bot script for that gets its data from wunderground.com site for mIRC. It allows the abilty to get the weather, forecasts, alerts, and time form around the world.

 

I did see there was one for php but needed one for mIRC. weather.com only accepts US zipcodes, and there are users from across the world. This will work with US and outside zipcodes (ex: e2l1n5) or city and state (dallas,tx) or city,country (Sydney,AU or Sydney, Australia) and airports (LAX)

 

Commands:

!w or !weather [zipcode|city,state|city,country|airport]

will return current conditions.

 

!forecast [zipcode|city,state|city,country|airport]

will give detailed 3 day forecast (for us)

 

!forecast5 [zipcode|city,state|city,country|airport]

will send 5 day forecast to $nick that requested. (to prevent chan flooding)

 

!alerts [zipcode|city,state|city,country|airport]

will tell you if there are any weather alerts in your area.

 

Script uses 1 socket for all above commands, but each command links to slightly different xml page.

It is setup right now to grab all the data from the xml page and set them to all to corresponding variables.(long list of if statements) To view what it returns, just comment out the unset %wu_* at the bottom of the script. execute the script (ex: !weather 90210) and then look at your variables.

 

on sockclose you will find a lot of $+ and $chr(##) actions. This is to squish the resuts together and to add items like °F ($chr(176),F) or I have spacers like -|- ($chr(45) $+ $chr(124) $+ $chr(45))

ex: msg %wu_chan %wu_full $+ : %wu_weather and $+(%wu_temp_f,$chr(176),F,$chr(40),%wu_temp_c,$chr(176),C,$chr(41))

gives you City,State: Overcast and 34°F(1°C)

 

It is on its first final draft. Feel free to give suggestions on improvements.

 

Edited 2009-12-14:

Updated !alerts to properly msg back all alerts

Updated !alerts to also respond to !alert

Updated !forecast results to correctly give the 3rd result based on if second result is current day or next day (tomorrow)

Created %var to put together forecast results making them easier to edit additions to it (F,C ° stuff)

 

Edited 2009-12-26:

Removed 'write -i wu_temp.txt %wu_temp' line not needed. Only was there for testing. Will run faster with out that line.

Edited 2010-01-25

Corrected set -n $2 to change all spaces to +(so it will work)

Added !alertinfo = will send detailed alert info to user

Edited 2010-04-10: corrected a small glitch on reading from the xml data.

Edited 2010-08-12: Minor. Removed Botabuse. Was a separate bot flood protecting script (see: http://www.hawkee.com/snippet/7858/ )

 

 

 

 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;; weather underground for mIRC ;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;by eqrunner ;;;;

 

/*

!w or !weather [zipcode|city,state|city,country|airport] will return current conditions.

!forecast [zipcode|city,state|city,country|airport] will give detailed 3 day forecast (for us)

!forecast5 [zipcode|city,state|city,country|airport] will send 5 day forecast to $nick that requested. (to prevent chan flooding)

!alerts [zipcode|city,state|city,country|airport] will tell you if there are any weather alerts in your area.

!alertinfo [zipcode|city,state|city,country|airport] will send $nick the detailed report of alerts in said area

!time [zipcode|city,state|city,country|airport] will return current time.

 

Notes from wunderground:

We don't support old style abbreviations like Conn. for Connecticut, use CT

If you are searching for an international city, try the name of the country or province

Don't use provinces for non-us cities (ie: Vancouver, BC)

Zipcodes only work in Canada, UK and the US

*/

 

 

on $*:text:/^[!](w|weather|forecast|forecast5|alert|alerts|alertinfo|alertsinfo|time)/Si:#: {

   unset %wu_*

  if ($2 == $null) { .notice $nick Please specify a location $1 [zipcode|city,state|city,country|airport] | halt }

  set %wu_command $1

  set %wu_address $replace($2-,$chr(32),$chr(43)) 

  set %wu_nick $nick

  set %wu_network $network

  set %wu_chan $chan

 

  if (%wu_command == !weather) || (%wu_command == !w) || (%wu_command == !time) { 

    set %wu_link $+(/auto/wui/geo/WXCurrentObXML/index.xml?query=,%wu_address)

    set %wu_host api.wunderground.com

    sockopen wunderground %wu_host 80

  }

  if (%wu_command == !forecast) || (%wu_command == !forecast5) { 

    set %wu_link $+(/auto/wui/geo/ForecastXML/index.xml?query=,%wu_address)

    set %wu_host www.wunderground.com

    sockopen wunderground %wu_host 80

 

  }

  if (%wu_command == !alert) set %wu_command !alerts

  if (%wu_command == !alertsinfo) set %wu_command !alertinfo

  if (%wu_command == !alerts) || (%wu_command == !alertinfo) { 

    ;echo -s pass

    set %wu_link $+(/auto/wui/geo/AlertsXML/index.xml?query=,%wu_address)

    set %wu_host www.wunderground.com

    sockopen wunderground %wu_host 80

  }

 

  ;echo -s LINK: %wu_link

}

 

 

on *:sockopen:wunderground: {

 

  ;sockwrite -n $sockname GET %wu_link XML/1.0

  sockwrite -n $sockname GET %wu_link

  sockwrite -n $sockname Host: %wu_host

  sockwrite -n $sockname $crlf

}

 

on *:sockread:wunderground: {

  sockread %wu_temp

  ;echo -s %wu_temp

 

  if (%wu_command == !weather) || (%wu_command == !w) || (%wu_command == !time) { 

    ; local info

    if ( isin %wu_temp) && (%wu_full == $null) %wu_full = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_city == $null) %wu_city = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_state == $null) %wu_state = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_state_name == $null) %wu_state_name = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_country == $null)  %wu_country = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_country_iso3166 == $null) %wu_country_iso3166 = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_zip == $null)  %wu_zip = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_latitude == $null) %wu_latitude = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_longitude == $null) %wu_longitude = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) && (%wu_elevation == $null) %wu_elevation = $remove(%wu_temp,,,$chr(9)) 

 

    if ( isin %wu_temp) %wu_local_time = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_local_time_rfc822 = $remove(%wu_temp,,,$chr(9)) 

 

    ; current weather

    if ( isin %wu_temp) %wu_weather = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_temperature_string = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_temp_f = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_temp_c = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_relative_humidity = $remove(%wu_temp,,,$chr(9)) 

 

    ; wind

    if ( isin %wu_temp) %wu_wind_string = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_wind_dir = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_wind_degrees = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_wind_mph = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_wind_gust_mph = $remove(%wu_temp,,,$chr(9)) 

 

    if ( isin %wu_temp) %wu_pressure_string = $remove(%wu_temp,,,$chr(9)) 

    if ( isin %wu_temp) %wu_pressure_mb = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_pressure_in = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_dewpoint_string = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_dewpoint_f = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_dewpoint_c = $remove(%wu_temp,,,$chr(9))

 

    if ( isin %wu_temp) %wu_heat_index_string = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_heat_index_f = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_heat_index_c = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_windchill_string = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_windchill_f = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_windchill_c = $remove(%wu_temp,,,$chr(9))

 

    if ( isin %wu_temp) %wu_visibility_mi = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) %wu_visibility_km = $remove(%wu_temp,,,$chr(9))

  }

 

  if (%wu_command == !forecast) || (%wu_command == !forecast5) {

    if ( isin %wu_temp) set %wu_period $remove(%wu_temp,,,$chr(9),$chr(32))

    if ( isin %wu_temp) set %wu_xtemp 1

    if ( isin %wu_temp) set %wu_xtemp 2

    if ( isin %wu_temp) set %wu_simpleforecast 1

 

    if ( isin %wu_temp) && (%wu_period == 1) %wu_f1_title = $remove(%wu_temp,,,$chr(9),$chr(32))

    if ( isin %wu_temp) && (%wu_period == 1) %wu_f1_fcttext = $remove(%wu_temp,,,$chr(9))

    if ( isin %wu_temp) && (%wu_period == 2) %wu_f2_title = $remove(%wu_temp,,,$chr(9),$chr(32))

    if ( isin %wu_temp) && (%wu_period == 2) %wu_f2_fcttext = $remove(%wu_temp,,,$chr(9))

 

    if (%wu_simpleforecast == 1) {

      if ( isin %wu_temp) set $+(%,wu_P,%wu_period,_weekday) $remove(%wu_temp,,,$chr(9),$chr(32))

      if ( isin %wu_temp) set $+(%,wu_P,%wu_period,_conditions) $remove(%wu_temp,,,$chr(9))

      if (%wu_xtemp == 1) {

        if ( isin %wu_temp) set $+(%,wu_P,%wu_period,_highf) $remove(%wu_temp,,,$chr(9),$chr(32))

        if ( isin %wu_temp) set $+(%,wu_P,%wu_period,_highc) $remove(%wu_temp,,,$chr(9),$chr(32))

      }

      if (%wu_xtemp == 2) {

        if ( isin %wu_temp) set $+(%,wu_P,%wu_period,_lowf) $remove(%wu_temp,,,$chr(9),$chr(32))

        if ( isin %wu_temp) set $+(%,wu_P,%wu_period,_lowc) $remove(%wu_temp,,,$chr(9),$chr(32))

      }

    }

  }

  if (%wu_command == !alerts) || (%wu_command == !alertinfo) { 

    ;echo -s %wu_temp

    set -n %wu_ac 
Link to comment
Share on other sites



×
×
  • Create New...