Skip to content

Commit

Permalink
Changed NOAA data endpoint, upgrade to Go 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
FileGo committed Oct 17, 2023
1 parent 347826e commit aadd433
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM golang AS build-env
WORKDIR /app
ADD . /app/
RUN go get -d -v ./...
ENV CGO_ENABLED=0
RUN go build -o /go/bin/app

FROM gcr.io/distroless/base
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This projects creats a [Telegram](https://telegram.org/) bot, written in Go that receives one or multiple airport identifiers (4-letter ICAO or 3-letter IATA), separated by comma or space and returns current (METAR) and forecasted weather (TAF) for the requested airports.

It uses NOAA Aviation Weather Center's [Text Data Server](https://www.aviationweather.gov/dataserver) to retrieve data. Requests require ICAO airport code. Default interval for METAR/TAF is 12 hours, but can be overriden by providing NOAA_INTERVAL environmental variable.
It uses NOAA Aviation Weather Center's [Text Data Server](https://aviationweather.gov/data/api/) to retrieve data. Requests require ICAO airport code. Default interval for METAR/TAF is 12 hours, but can be overriden by providing NOAA_INTERVAL environmental variable.

It also provides a JSON file (airports.json), which has been created with data from [OpenFlights](https://openflights.org/data.html#airport). It stores a large majority of worldwide airports and it is used to lookup ICAO and IATA codes as required.
It also provides a JSON file (airports.json), which has been created with data from [OpenFlights](https://openflights.org/data.html#airport). It stores a large majority of worldwide airports and it is used to lookup ICAO and IATA codes as required.

In order to make use of Telegram, a bot needs to be [created](https://core.telegram.org/bots#6-botfather) and token passed as an environmental variable. By default it uses the *updates* method of retrieving requests, however if both WEBHOOK_URL and WEBHOOK_PORT environmental variables are set, it will utilise the webhook.

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module github.com/FileGo/AvWxTelegramBot

go 1.18
go 1.21

require (
github.com/stretchr/testify v1.7.1
github.com/stretchr/testify v1.8.4
github.com/yanzay/tbot/v2 v2.2.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yanzay/tbot/v2 v2.2.0 h1:bK1+XTwY59IskXpwtHc/ItfU2uELTTqYP3pajfBaPeM=
github.com/yanzay/tbot/v2 v2.2.0/go.mod h1:q0+8JblBq9tLAnKHdBIZsHwDvMS9TfO6mNfaAk1VrHg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

const dbPath = "airports.json"

const urlPrefix = "https://aviationweather.gov/cgi-bin/data/dataserver.php"

// GetAirportCodes returns array of ICAO codes from a message string
func GetAirportCodes(input string) (output []string) {
output = []string{}
Expand Down
5 changes: 2 additions & 3 deletions noaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"sync"
)

Expand Down Expand Up @@ -126,7 +125,7 @@ func (env *Env) getData(dataSource string, ICAO string, data chan outputData, wg
var out outputData
defer wg.Done()

url := fmt.Sprintf("https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=%s&requestType=retrieve&format=xml&stationString=%s&hoursBeforeNow=%d", dataSource, ICAO, env.NOAAinterval)
url := fmt.Sprintf("%s?dataSource=%s&requestType=retrieve&format=xml&stationString=%s&hoursBeforeNow=%d", urlPrefix, dataSource, ICAO, env.NOAAinterval)

response, err := env.httpClient.Get(url)
if err != nil {
Expand All @@ -136,7 +135,7 @@ func (env *Env) getData(dataSource string, ICAO string, data chan outputData, wg
return
}

buf, err := ioutil.ReadAll(response.Body)
buf, err := io.ReadAll(response.Body)
if err != nil {
out.err = err
data <- out
Expand Down

0 comments on commit aadd433

Please sign in to comment.