You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-weather/main.go

40 lines
871 B

package main
import (
"flag"
"fmt"
"os"
)
func main() {
//set up the flags for the program to use!
var city, code, api_key string
flag.StringVar(&city, "city", "London", "Enter city e.g. London")
flag.StringVar(&code, "code", "uk", "Enter Code e.g. uk")
flag.StringVar(&api_key, "api", "none", "Enter you api key here")
flag.Parse()
full := "https://api.openweathermap.org/data/2.5/weather?q=" + city + "," + code + "&units=metric" + "&appid=" + api_key + ""
//read webpage
html, err := loadWebPage(full)
if err != nil {
fmt.Println("4xx error, please try again!")
os.Exit(1)
}
//Create file
createFile(string(html))
//Load the file
data, err := loadJson("weather.json")
if err != nil {
fmt.Println("Cannot load weather.json file!")
}
//Print the weather!
printWeather(data)
//remove the file at the end
removeFile("weather.json")
}