Skip to content

Commit

Permalink
update scripts from fetch to http get (nushell#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdncred committed Feb 10, 2023
1 parent f23fbf5 commit 9bad97e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions weather/get-weather.nu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def locations [] {
}

def get_my_location [index: int] {
let loc_json = (fetch (locations | select $index).0.location)
let loc_json = (http get (locations | select $index).0.location)
let city_column = (locations | select $index).0.city_column
let state_column = (locations | select $index).0.state_column
let country_column = (locations | select $index).0.country_column
Expand Down Expand Up @@ -45,7 +45,7 @@ def get_location_by_ip [locIdx: int, token: string] {
let URL_QUERY_LOCATION = "https://api.openweathermap.org/geo/1.0/direct"
let location = (get_my_location $locIdx)
let url = $"($URL_QUERY_LOCATION)?q=($location)&limit=5&appid=($token)"
fetch $url
http get $url
}

def show-error [msg label err] {
Expand All @@ -68,8 +68,8 @@ def get_weather_by_ip [locIdx: int, units: string, token: string] {
let units = "imperial"
let url = $"($URL_WEATHER)?lat=($coords.lat.0)&lon=($coords.lon.0)&units=($units)&appid=($token)"
let url_forecast = $"($URL_FORECAST)?lat=($coords.lat.0)&lon=($coords.lon.0)&units=($units)&appid=($token)"
let weather = (fetch $url)
let forecast_data = (fetch $url_forecast)
let weather = (http get $url)
let forecast_data = (http get $url_forecast)
let forecast = ($forecast_data.list | each {|day|
{
id: ($day.weather.0.id)
Expand Down Expand Up @@ -106,8 +106,8 @@ def get_weather_by_ip [locIdx: int, units: string, token: string] {
let units = "metric"
let url = $"($URL_WEATHER)?lat=($coords.lat.0)&lon=($coords.lon.0)&units=($units)&appid=($token)"
let url_forecast = $"($URL_FORECAST)?lat=($coords.lat.0)&lon=($coords.lon.0)&units=($units)&appid=($token)"
let weather = (fetch $url)
let forecast_data = (fetch $url_forecast)
let weather = (http get $url)
let forecast_data = (http get $url_forecast)
let forecast = ($forecast_data.list | each {|day|
{
id: ($day.weather.0.id)
Expand Down
14 changes: 7 additions & 7 deletions weather/weatherdark.nu
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ def locations [] {

def get_location [index: int] {
let wifi = (iwgetid -r)
let loc_json = (fetch (locations | select $index).0.location)
let loc_json = (http get (locations | select $index).0.location)

# if ip address in your home isn't precise, you can force a location
if $wifi =~ "my_wifi" { "your_lat,your_lon" } else { $"($loc_json.lat),($loc_json.lon)" }
}

# dark sky
def fetch_api [loc] {
def http get_api [loc] {
let apiKey = "ds_api_key"
let options = "?lang=en&units=si&exclude=minutely,hourly,flags"

let url = $"https://api.darksky.net/forecast/($apiKey)/($loc)($options)"

fetch $url
http get $url
}

# street address
def get_address [loc] {
let mapsAPIkey = "maps_api_key"
let url = $"https://maps.googleapis.com/maps/api/geocode/json?latlng=($loc)&sensor=true&key=($mapsAPIkey)"

(fetch $url).results.0.formatted_address
(http get $url).results.0.formatted_address
}

# wind description (adjust to your liking)
Expand All @@ -60,7 +60,7 @@ def get_airCond [loc] {
let lat = (echo $loc | split row ",").0
let lon = (echo $loc | split row ",").1
let url = $"https://api.airvisual.com/v2/nearest_city?lat=($lat)&lon=($lon)&key=($apiKey)"
let aqius = (fetch $url).data.current.pollution.aqius
let aqius = (http get $url).data.current.pollution.aqius

# clasification (standard)
if $aqius < 51 { "Good" } else if $aqius < 101 { "Moderate" } else if $aqius < 151 { "Unhealthy for some" } else if $aqius < 201 { "Unhealthy" } else if $aqius < 301 { "Very unhealthy" } else { "Hazardous" }
Expand All @@ -69,7 +69,7 @@ def get_airCond [loc] {
# parse all the information
def get_weather [loc] {

let response = (fetch_api $loc)
let response = (http get_api $loc)
let address = (get_address $loc)
let air_cond = (get_airCond $loc)

Expand Down Expand Up @@ -156,7 +156,7 @@ export def-env get_weather_by_interval [INTERVAL_WEATHER] {

def get_weather_for_prompt [loc] {

let response = (fetch_api $loc)
let response = (http get_api $loc)

## current conditions
let cond = $response.currently.summary
Expand Down

0 comments on commit 9bad97e

Please sign in to comment.