Advertisement
SReject

$getWeather

Jun 23rd, 2015
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 3.41 KB | None | 0 0
  1. alias -l forecastApiKey return PUT_YOUR_FORECAST.IO_API_KEY_HERE
  2.  
  3. alias getWeather {
  4.   var %latitude, %longitude, %location, %condition, %visibility, %temperature, %feelsLike, %dewPoint, %humidity, %windSpeed, %windBearing, %forecast, %visibilityMetric, %temperatureMetric, %feelsLikeMetric, %dewPointMetric, %windSpeedMetric, %windDirection, %precipType, %url, %cloudCover, %pressure, %ozone, %precipProbability, %precipIntensity
  5.   if ($0 == 1) {
  6.     JSONOpen -ud GetWeatherGeoCode http://maps.googleapis.com/maps/api/geocode/json?address= $+ $urlencode($1)
  7.     if ($jsonerror) { return }
  8.     %location = $JSON(GetWeatherGeoCode, results, 0, formatted_address)
  9.     %latitude = $JSON(GetWeatherGeoCode, results, 0, geometry, location, lat)
  10.     %longitude = $JSON(GetWeatherGeoCode, results, 0, geometry, location, lng)
  11.   }
  12.   elseif ($0 == 2 && $1 isnum -90-90 && $2 isnum -180-180) {
  13.     %location = $1 $+ $chr(44) $2
  14.     %latitude = $1
  15.     %longitude = $2
  16.   }
  17.   if (!$len(%latitude) && !$len(%longitude)) {
  18.     return
  19.   }
  20.   JSONOpen -ud getForecast https://api.forecast.io/forecast/ $+ $forecastAPIKey $+ / $+ %latitude $+ , $+ %longitude
  21.   if ($jsonerror) { return }
  22.   if ($json(getForecast, currently, windSpeed)) {
  23.     %windSpeed = $v1
  24.     %windSpeedMetric = $round($calc(%windSpeed * 1.61), 1)
  25.     %windBearing     = $json(getForecast, currently, windBearing)
  26.     %windDirection   = $gettok(N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW, $calc( (%windBearing + 11.25) % 360 / 22.5 + 1), 32)
  27.   }
  28.   else {
  29.     %windSpeed = 0
  30.     %windSpeedMetric = 0
  31.     %windBearing = N/A
  32.     %windDirection = N/A
  33.   }
  34.   if (%precipIntensity) {
  35.     %precipType = $json(getForecast, currently, precipType)
  36.   }
  37.   else {
  38.     %precipType = N/A
  39.   }
  40.   %url               = http://forecast.io/#/f/ $+ %latitude $+ , $+ %longitude
  41.   %condition         = $json(getForecast, currently, summary)
  42.   %forecast          = $json(getForecast, daily, summary)
  43.   %humidity          = $calc($json(getForecast, currently, humidity) * 100)
  44.   %visibility        = $iif($json(getForecast, currently, visibility), $v1, 0)
  45.   %visibilityMetric  = $round($calc( %visibility * 1.61 ),1)
  46.   %temperature       = $json(getForecast, currently, temperature)
  47.   %temperatureMetric = $round($calc(( %temperature - 32) * 5/9),1)
  48.   %feelsLike         = $json(getForecast, currently, apparentTemperature)
  49.   %feelsLikeMetric   = $round($calc(( %feelsLike - 32) * 5/9),1)
  50.   %dewPoint          = $json(getForecast, currently, dewPoint)
  51.   %dewPointMetric    = $round($calc(( %dewPoint - 32) * 5/9),1)
  52.   %cloudCover        = $calc($json(getForecast, currently, cloudCover) * 100)
  53.   %pressure          = $json(getForecast, currently, pressure)
  54.   %ozone             = $json(getForecast, currently, ozone)
  55.   %precipProbability = $calc($json(getForecast, currently, precipProbability) * 100)
  56.   %precipIntensity   = $json(getForecast, currently, precipIntensity)
  57.  
  58.   return %location -- Cond: %condition -- Vis: %visibility $+ mi/ $+ %visibilityMetric $+ km -- Temp: %temperature $+ °F/ $+ %temperatureMetric $+  $+ °C -- Windchill: %feelsLike $+ °F/ $+ %feelsLikeMetric $+  $+ °C -- Dew Point: %dewPoint $+ °F/ $+ %dewPointMetric $+ °C -- Humidity: %humidity $+ % -- Wind Speed: %windSpeed $+ mph/ $+ %windSpeedMetric $+ kph -- Wind Bearing: %windBearing -- Forecast: %forecast -- URL: %url
  59. }
  60. alias -l urlencode return $regsubex($1-, /([^a-z\d_-])/gi, % $+ $base($asc(\t), 10, 16, 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement