Skip to content

Commit

Permalink
make custom data override checkwx instead of replace
Browse files Browse the repository at this point in the history
  • Loading branch information
evogelsa committed Apr 15, 2024
1 parent d100535 commit 885fa51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ each parameter.
mission brief.
* `use-custom-data`: boolean
* If true, Real Weather will load METAR data from a checkwx.json file
instead of accessing the CheckWX API. This data must be in the same format
CheckWX would provide. See [examples/checkwx.json](examples/checkwx.json)
and [checkwxapi.com](https://www.checkwxapi.com/documentation/metar) for
more info. Only the parameters shown in the example are currently
supported.
and overwrite data from the CheckWX API. This data must be in the same
format CheckWX would provide. See
[examples/checkwx.json](examples/checkwx.json) and
[checkwxapi.com](https://www.checkwxapi.com/documentation/metar) for more
info. Only the parameters shown in the example are currently supported.
If not all parameters are given, the missing data will come from CheckWX.
* `options`
* `update-time`: boolean
* Disable/enable Real Weather modifying your mission time.
Expand Down
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ func getWx() weather.WeatherData {
debugCheckWx = true
}

data, err = weather.GetWeather(config.Get().METAR.ICAO, config.Get().APIKey)
if err != nil {
log.Printf("Error getting weather, using default: %v\n", err)
data = weather.DefaultWeather
}

if debugCheckWx {
log.Println("Using custom weather data from file...")
log.Println("Overriding weather with custom data from file...")
b, err := os.ReadFile("checkwx.json")
if err != nil {
log.Fatalf("Could not read checkwx.json: %v", err)
Expand All @@ -134,13 +140,6 @@ func getWx() weather.WeatherData {
log.Fatalf("Could not parse checkwx.json: %v", err)
}
log.Println("Parsed weather data: ")

} else {
data, err = weather.GetWeather(config.Get().METAR.ICAO, config.Get().APIKey)
if err != nil {
log.Printf("Error getting weather, using default: %v\n", err)
data = weather.DefaultWeather
}
}

return data
Expand Down

0 comments on commit 885fa51

Please sign in to comment.