Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias -l forecastApiKey return PUT_YOUR_FORECAST.IO_API_KEY_HERE
- alias getWeather {
- 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
- if ($0 == 1) {
- JSONOpen -ud GetWeatherGeoCode http://maps.googleapis.com/maps/api/geocode/json?address= $+ $urlencode($1)
- if ($jsonerror) { return }
- %location = $JSON(GetWeatherGeoCode, results, 0, formatted_address)
- %latitude = $JSON(GetWeatherGeoCode, results, 0, geometry, location, lat)
- %longitude = $JSON(GetWeatherGeoCode, results, 0, geometry, location, lng)
- }
- elseif ($0 == 2 && $1 isnum -90-90 && $2 isnum -180-180) {
- %location = $1 $+ $chr(44) $2
- %latitude = $1
- %longitude = $2
- }
- if (!$len(%latitude) && !$len(%longitude)) {
- return
- }
- JSONOpen -ud getForecast https://api.forecast.io/forecast/ $+ $forecastAPIKey $+ / $+ %latitude $+ , $+ %longitude
- if ($jsonerror) { return }
- if ($json(getForecast, currently, windSpeed)) {
- %windSpeed = $v1
- %windSpeedMetric = $round($calc(%windSpeed * 1.61), 1)
- %windBearing = $json(getForecast, currently, windBearing)
- %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)
- }
- else {
- %windSpeed = 0
- %windSpeedMetric = 0
- %windBearing = N/A
- %windDirection = N/A
- }
- if (%precipIntensity) {
- %precipType = $json(getForecast, currently, precipType)
- }
- else {
- %precipType = N/A
- }
- %url = http://forecast.io/#/f/ $+ %latitude $+ , $+ %longitude
- %condition = $json(getForecast, currently, summary)
- %forecast = $json(getForecast, daily, summary)
- %humidity = $calc($json(getForecast, currently, humidity) * 100)
- %visibility = $iif($json(getForecast, currently, visibility), $v1, 0)
- %visibilityMetric = $round($calc( %visibility * 1.61 ),1)
- %temperature = $json(getForecast, currently, temperature)
- %temperatureMetric = $round($calc(( %temperature - 32) * 5/9),1)
- %feelsLike = $json(getForecast, currently, apparentTemperature)
- %feelsLikeMetric = $round($calc(( %feelsLike - 32) * 5/9),1)
- %dewPoint = $json(getForecast, currently, dewPoint)
- %dewPointMetric = $round($calc(( %dewPoint - 32) * 5/9),1)
- %cloudCover = $calc($json(getForecast, currently, cloudCover) * 100)
- %pressure = $json(getForecast, currently, pressure)
- %ozone = $json(getForecast, currently, ozone)
- %precipProbability = $calc($json(getForecast, currently, precipProbability) * 100)
- %precipIntensity = $json(getForecast, currently, precipIntensity)
- 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
- }
- 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