Skip to content

Commit 54d2394

Browse files
author
loraxipam
committed
Issue #1 - fixes for new api.weatherstem.com
1 parent cff27b0 commit 54d2394

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.swp
2+
weatherstem.json

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ When you just want a quick peek at the local weather, here's a tool to query wea
1111

1212
You'll need to create a small config file with your weatherstem.com API key and the local domain URL that you will use. You might have one or two favorite stations to query, so you will need their short name. Here's the example config file. Call it `weatherstem.json` and put it in your `.config` directory. Or leave it in your current directory. Or put it in `~/.weatherstem.json` and it will work.
1313

14-
`{"version":"2.0","api_key":"yourKeyGoesHere","stations":["firstOne","maybeTwo","doubtfulThree"],"api_url":"https://domain.weatherstem.com","me":{"lat":45.0,"lon":-123.0}}`
14+
```
15+
{"version": "3.0",
16+
"api_key": "yourKeyGoesHere",
17+
"stations":
18+
["firstOne@domain.weatherstem.com",
19+
"maybeTwo@domain.weatherstem.com",
20+
"someThird@domain.weatherstem.com"],
21+
"api_url": "https://api.weatherstem.com/api",
22+
"me": {"lat": 45.0, "lon": -123.0}}
23+
```
1524

1625
FYI, if you run it with no config file, it will complain and show you an example as above. Cut and paste for the win.
1726

@@ -36,4 +45,4 @@ If you want boring compass rose directions, use `-rose`.
3645

3746
I use the alternate compass rose because I love to say the word "Tramontana."
3847

39-
If you want to query stations in different domains, you'll need two directories with separate config files.
48+
The new (Aug 2020) v1 API station ID format allows querying stations in different domains using the same config file. :raised_hands:

weatherstem.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
const (
2626
// Version of the configuration file layout
27-
configSettingsVersion = "2.0"
27+
configSettingsVersion = "3.0"
2828
)
2929

3030
// WeatherInfo struct
@@ -300,7 +300,9 @@ func (config *configSettings) getConfigSettings(inputFile string) (err error) {
300300
log.Panicln("Cannot unmarshal config", inputFile)
301301
}
302302
} else if configVersion <= configSettingsVersion {
303-
log.Printf("WARNING: Using a version %s config file in a version %s app. Your location could become NYC.\n", configVersion, configSettingsVersion)
303+
log.Printf("WARNING: Using a version %s config file in a version %s app.\n", configVersion, configSettingsVersion)
304+
log.Printf("Version 2 added your geolocation. Your location could become NYC.\n")
305+
log.Printf("Version 3 uses the Aug 2020 API v1 'station@domain.weatherstem.com' syntax.\n")
304306
err = json.Unmarshal(configJSON, &config)
305307
if err != nil {
306308
log.Panicln("Cannot unmarshal config", inputFile)
@@ -470,7 +472,7 @@ func main() {
470472
err = findConfigSettings(&myConfig)
471473
if err != nil {
472474
log.Println("Config file not found. It should look like this and be in 'weatherstem.json', either in the current or in your $HOME/.config directory.")
473-
log.Println(`{"version":"2.0","api_url":"https://domain.weatherstem.com/api","api_key":"yourApiKey","stations":["station1","stationX"],"me":{"lat":43.14,"lon":-111.275}}`)
475+
log.Println(`{"version":"3.0","api_url":"https://api.weatherstem.com/api","api_key":"yourApiKey","stations":["station1@domain.weatherstem.com","stationX@domain.weatherstem.com"],"me":{"lat":43.14,"lon":-111.275}}`)
474476
os.Exit(3)
475477
}
476478

0 commit comments

Comments
 (0)