Skip to content

Commit

Permalink
add option to use custom weather data
Browse files Browse the repository at this point in the history
  • Loading branch information
evogelsa committed Apr 15, 2024
1 parent 6b6d968 commit d100535
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ resource.syso

# testing files
config.json
checkwx.json
mission.miz
realweather.miz
tmp/
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ each parameter.
"log": "logfile.log" // path of log file, "" disables
},
"metar": {
"icao": "KDLH", // ICAO of the aiport to fetch METAR from
"runway-elevation": 0, // elevation of runway in meters MSL
"remarks": "", // addtional remarks for METAR, customization only
"add-to-brief": true // add METAR text to bottom of mission brief
"icao": "KDLH", // ICAO of the aiport to fetch METAR from
"runway-elevation": 0, // elevation of runway in meters MSL
"remarks": "", // addtional remarks for METAR, customization only
"add-to-brief": true, // add METAR text to bottom of mission brief
"use-custom-data": false // use custom data from checkwx.json file
},
"options": {
"update-time": true, // set to false to disable time being updated
Expand Down Expand Up @@ -133,6 +134,13 @@ each parameter.
* `add-to-brief`: boolean
* If true, Real Weather will add the generated METAR to the bottom of your
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.
* `options`
* `update-time`: boolean
* Disable/enable Real Weather modifying your mission time.
Expand Down
79 changes: 0 additions & 79 deletions checkwx.json

This file was deleted.

1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Configuration struct {
RunwayElevation int `json:"runway-elevation"`
Remarks string `json:"remarks"`
AddToBrief bool `json:"add-to-brief"`
UseCustomData bool `json:"use-custom-data"`
} `json:"metar"`
Options struct {
UpdateTime bool `json:"update-time"`
Expand Down
3 changes: 2 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"icao": "UGKO",
"runway-elevation": 160,
"remarks": "RMK Generated by DCS Real Weather",
"add-to-brief": true
"add-to-brief": true,
"use-custom-data": false
},
"options": {
"update-time": true,
Expand Down
44 changes: 44 additions & 0 deletions examples/checkwx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"results": 1,
"data": [
{
"icao": "UGKO",
"barometer": {
"hg": 30.15
},
"clouds": [
{
"code": "OVC",
"meters": 549
},
{
"code": "BKN",
"meters": 1372
}
],
"dewpoint": {
"celsius": 11
},
"observed": "2024-04-13T01:00:00",
"station": {
"geometry": {
"coordinates": [
42.482393,
42.176768
]
}
},
"temperature": {
"celsius": 12
},
"visibility": {
"meters_float": 8000
},
"wind": {
"degrees": 220,
"speed_mps": 2,
"gust_mps": 0
}
}
]
}
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
//go:generate goversioninfo versioninfo/versioninfo.json

import (
"bytes"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -108,17 +109,32 @@ func getWx() weather.WeatherData {
var err error
var data weather.WeatherData

// use value from config if exists. CLI argument will override a false
// parameter in the config
if config.Get().METAR.UseCustomData {
debugCheckWx = true
}

if debugCheckWx {
log.Println("Debugging CheckWx. Reading data from file...")
log.Println("Using custom weather data from file...")
b, err := os.ReadFile("checkwx.json")
if err != nil {
log.Fatalf("Could not read checkwx.json: %v", err)
}

var minify bytes.Buffer
if err := json.Compact(&minify, b); err == nil {
log.Println("Read weather data: ", minify.String())
} else {
log.Println("Couldn't minify custom weather data:", err)
}

err = json.Unmarshal(b, &data)
if err != nil {
log.Fatalf("Could not parse checkwx.json: %v", err)
}
log.Println("Parsed weather data")
log.Println("Parsed weather data: ")

} else {
data, err = weather.GetWeather(config.Get().METAR.ICAO, config.Get().APIKey)
if err != nil {
Expand Down

0 comments on commit d100535

Please sign in to comment.