This commit is contained in:
Tyrel Souza 2020-02-25 16:29:43 -05:00
parent 9d3bba7a93
commit 333d430ac2
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
3 changed files with 53 additions and 4 deletions

7
go.mod
View File

@ -2,4 +2,9 @@ module gitlab/tyrelsouza/gfsmos
go 1.13
require github.com/urfave/cli/v2 v2.1.1
require (
github.com/antchfx/xpath v1.1.4
github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0
github.com/urfave/cli/v2 v2.1.1
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0
)

10
go.sum
View File

@ -1,4 +1,8 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/antchfx/xpath v1.1.4 h1:naPIpjBGeT3eX0Vw7E8iyHsY8FGt6EbGdkcd8EZCo+g=
github.com/antchfx/xpath v1.1.4/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0 h1:JaCC8jz0zdMLk2m+qCCVLLLM/PL93p84w4pK3aJWj60=
github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0/go.mod h1:LzD22aAzDP8/dyiCKFp31He4m2GPjl0AFyzDtZzUu9M=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@ -9,5 +13,11 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs=
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

40
main.go
View File

@ -2,18 +2,28 @@ package main
import (
"fmt"
"github.com/antchfx/xpath"
"github.com/antchfx/xquery/html"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
cli "github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "boom",
Usage: "make an explosive entrance",
Name: "GFS MOS",
Usage: "Parse NOAA's GFS MOS for a given airport",
Action: func(c *cli.Context) error {
fmt.Println("boom! I say!")
airport := strings.ToUpper(c.Args().First())
if airport == "" {
return cli.NewExitError("please pass the airport's ICAO as an argument", 1)
}
pre := getDataFromPre(airport)
fmt.Println(pre)
return nil
},
}
@ -23,3 +33,27 @@ func main() {
log.Fatal(err)
}
}
func getDataFromPre(airport string) string {
url := fmt.Sprintf("https://www.nws.noaa.gov/cgi-bin/mos/getmav.pl?sta=%s", airport)
response, err := http.Get(url)
defer response.Body.Close()
if err != nil {
log.Fatal(err)
}
bytes, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
doc, err := htmlquery.Parse(string(bytes))
if err != nil{
panic(err)
}
for _, n := range htmlquery.Find(doc, "//a/@href") {
fmt.Printf("%s \n", htmlquery.SelectAttr(n, "href")) // output href
}
return string(bytes)
}