@@ -6,7 +6,7 @@ def locations [] {
6
6
[location city_column state_column country_column lat_column lon_column ];
7
7
[" http://ip-api.com/json/" city region countryCode lat lon ]
8
8
[" https://ipapi.co/json/" city region_code country_code latitude longitude ]
9
- [" https://freegeoip.app/json/" city region_code country_code latitude longitude ]
9
+ # ["https://freegeoip.app/json/" city region_code country_code latitude longitude] # doesn't appear to be free any longer
10
10
[" https://ipwhois.app/json/" city region country_code latitude longitude ]
11
11
]
12
12
}
@@ -48,6 +48,11 @@ def get_location_by_ip [locIdx: int, token: string] {
48
48
fetch $url
49
49
}
50
50
51
+ def show-error [msg label err ] { 07 /02/2022 09 :24:44 AM
52
+ let span = (metadata $err ).span ;
53
+ error make {msg : $msg , label : {text : $label , start : $span.start , end : $span.end } }
54
+ }
55
+
51
56
def get_weather_by_ip [locIdx : int , units : string , token : string ] {
52
57
# units
53
58
# f = imperial aka Fahrenheit
@@ -56,10 +61,7 @@ def get_weather_by_ip [locIdx: int, units: string, token: string] {
56
61
let URL_FORECAST = " http://api.openweathermap.org/data/2.5/forecast/daily"
57
62
let coords = (get_location_by_ip $locIdx $token )
58
63
if ($coords | length ) > 1 {
59
- [
60
- [msg , labels , span ];
61
- [" Error getting location" , " There were more than one locations found" , ([[start , end ]; [0 , 1 ]])]
62
- ] | error make
64
+ show-error " Error getting location" " There were more than one locations found" $coords
63
65
}
64
66
65
67
if $units == " f" {
@@ -160,7 +162,7 @@ def get_icon_from_table [w] {
160
162
161
163
# Get the local weather by ip address
162
164
export def get_weather [
163
- -- locIdx(-l) : int # The location id 0-3
165
+ -- locIdx(-l) : int # The location id 0-2
164
166
-- units(-u) : string # The units "f" or "c"
165
167
] {
166
168
let token = " 85a4e3c55b73909f42c6a23ec35b7147"
0 commit comments