Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added satellite image flag #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"errors"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"

Expand All @@ -27,6 +30,7 @@ var (
server string
vrsn bool
client bool
satImage bool
geo geocode.Geocode
)

Expand All @@ -51,7 +55,7 @@ func init() {
flag.IntVar(&days, "d", 0, "No. of days to get forecast (shorthand)")
flag.BoolVar(&ignoreAlerts, "ignore-alerts", false, "Ignore alerts in weather output")
flag.BoolVar(&hideIcon, "hide-icon", false, "Hide the weather icons from being output")
flag.BoolVar(&noForecast, "no-forecast", false, "Hide the forecast for the next 16 hours")
flag.BoolVar(&satImage, "satImage", false, "Export the satellite image for U.S.A.")

flag.Usage = func() {
flag.PrintDefaults()
Expand Down Expand Up @@ -128,6 +132,31 @@ func main() {
if days > 0 {
forecast.PrintDaily(fc, days)
}

if satImage == true {
url := "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/GIFS/GOES16-CONUS-GEOCOLOR-625x375.gif"

response, err := http.Get(url)
if err != nil {
log.Fatal(err)
}

defer response.Body.Close()

image, err := os.Create("../latest_satellite.gif")
if err != nil {
log.Fatal(err)
}

_, err = io.Copy(image, response.Body)
if err != nil {
log.Fatal(err)
}
image.Close()

fmt.Println("The latest NOAA satellite image has been saved locally.")
}

}

func usageAndExit(message string, exitCode int) {
Expand Down