Skip to content

Commit

Permalink
Issue #1 - fixes for new api.weatherstem.com
Browse files Browse the repository at this point in the history
  • Loading branch information
loraxipam committed Aug 17, 2020
1 parent cff27b0 commit 54d2394
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
weatherstem.json
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ When you just want a quick peek at the local weather, here's a tool to query wea

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.

`{"version":"2.0","api_key":"yourKeyGoesHere","stations":["firstOne","maybeTwo","doubtfulThree"],"api_url":"https://domain.weatherstem.com","me":{"lat":45.0,"lon":-123.0}}`
```
{"version": "3.0",
"api_key": "yourKeyGoesHere",
"stations":
["[email protected]",
"[email protected]",
"[email protected]"],
"api_url": "https://api.weatherstem.com/api",
"me": {"lat": 45.0, "lon": -123.0}}
```

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.

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

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

If you want to query stations in different domains, you'll need two directories with separate config files.
The new (Aug 2020) v1 API station ID format allows querying stations in different domains using the same config file. :raised_hands:
8 changes: 5 additions & 3 deletions weatherstem.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
// Version of the configuration file layout
configSettingsVersion = "2.0"
configSettingsVersion = "3.0"
)

// WeatherInfo struct
Expand Down Expand Up @@ -300,7 +300,9 @@ func (config *configSettings) getConfigSettings(inputFile string) (err error) {
log.Panicln("Cannot unmarshal config", inputFile)
}
} else if configVersion <= configSettingsVersion {
log.Printf("WARNING: Using a version %s config file in a version %s app. Your location could become NYC.\n", configVersion, configSettingsVersion)
log.Printf("WARNING: Using a version %s config file in a version %s app.\n", configVersion, configSettingsVersion)
log.Printf("Version 2 added your geolocation. Your location could become NYC.\n")
log.Printf("Version 3 uses the Aug 2020 API v1 '[email protected]' syntax.\n")
err = json.Unmarshal(configJSON, &config)
if err != nil {
log.Panicln("Cannot unmarshal config", inputFile)
Expand Down Expand Up @@ -470,7 +472,7 @@ func main() {
err = findConfigSettings(&myConfig)
if err != nil {
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.")
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}}`)
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}}`)
os.Exit(3)
}

Expand Down

0 comments on commit 54d2394

Please sign in to comment.