mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-21 12:43:09 -05:00
Removed printWeather function
This commit is contained in:
parent
13f1e5da8c
commit
91eb2a5aa1
1 changed files with 7 additions and 26 deletions
|
@ -46,34 +46,15 @@ type application struct {
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func printWeather(app *application) {
|
|
||||||
|
|
||||||
var unitStr string
|
|
||||||
if app.Config.Units == "imperial" {
|
|
||||||
unitStr = "Farhenheit/mph"
|
|
||||||
} else {
|
|
||||||
unitStr = "Celsius/kph"
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("\nNote! A value of 0 or 0.00 indicates the data is not available at this time.")
|
|
||||||
fmt.Printf("Units: %s (%s)\n\n", app.Config.Units, unitStr)
|
|
||||||
fmt.Printf("Current temperature: %.2f\n", app.Forecast.Main.Temp)
|
|
||||||
fmt.Printf("Feels like: %.2f\n", app.Forecast.Main.FeelsLike)
|
|
||||||
fmt.Printf("High: %.2f\n", app.Forecast.Main.HighTemp)
|
|
||||||
fmt.Printf("Low: %.2f\n", app.Forecast.Main.LowTemp)
|
|
||||||
fmt.Printf("Pressure (hPa): %d\n", app.Forecast.Main.Pressure)
|
|
||||||
fmt.Printf("Humidty (%%): %d\n", app.Forecast.Main.Humidity)
|
|
||||||
fmt.Printf("Wind speed: %.2f\n", app.Forecast.Wind.Speed)
|
|
||||||
fmt.Printf("Gust: %.2f\n", app.Forecast.Wind.Gust)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
// Load .env
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read API_KEY from .env and create app
|
||||||
cfg := config{
|
cfg := config{
|
||||||
Units: "imperial",
|
Units: "imperial",
|
||||||
ApiKey: os.Getenv("API_KEY"),
|
ApiKey: os.Getenv("API_KEY"),
|
||||||
|
@ -87,8 +68,7 @@ func main() {
|
||||||
Version: version,
|
Version: version,
|
||||||
}
|
}
|
||||||
|
|
||||||
var option string
|
// Display main menu
|
||||||
|
|
||||||
fmt.Println("\n=====================================================")
|
fmt.Println("\n=====================================================")
|
||||||
fmt.Printf("| Welcome to the OpenWeatherMap-gRPC Client! v%s |\n", app.Version)
|
fmt.Printf("| Welcome to the OpenWeatherMap-gRPC Client! v%s |\n", app.Version)
|
||||||
fmt.Println("=====================================================")
|
fmt.Println("=====================================================")
|
||||||
|
@ -98,22 +78,23 @@ func main() {
|
||||||
fmt.Println(" - Advanced option: Enter exact location for anywhere in the world")
|
fmt.Println(" - Advanced option: Enter exact location for anywhere in the world")
|
||||||
fmt.Println(" - Advanced option: Change back and forth between imperial and metric units of measurement")
|
fmt.Println(" - Advanced option: Change back and forth between imperial and metric units of measurement")
|
||||||
|
|
||||||
|
var option string
|
||||||
|
// Menu loop
|
||||||
for option != "0" {
|
for option != "0" {
|
||||||
|
|
||||||
fmt.Print("\nMain Menu\n---------\n\n")
|
fmt.Print("\nMain Menu\n---------\n\n")
|
||||||
|
|
||||||
fmt.Println("1. Today's forecast (use current location, default)")
|
fmt.Println("1. Today's forecast (use current location, default)")
|
||||||
fmt.Println("2. Advanced options (Change units, precise location, etc.)")
|
fmt.Println("2. Advanced options (Change units, precise location, etc.)")
|
||||||
fmt.Print("0. Exit\n\n")
|
fmt.Print("0. Exit\n\n")
|
||||||
|
|
||||||
|
// Read user input
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
input, err := reader.ReadString('\n')
|
input, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
option = strings.TrimSuffix(input, "\n")
|
option = strings.TrimSuffix(input, "\n")
|
||||||
|
|
||||||
|
// Check user input
|
||||||
if option == "1" || option == "" {
|
if option == "1" || option == "" {
|
||||||
getLocation(&app)
|
getLocation(&app)
|
||||||
getCurrent(&app)
|
getCurrent(&app)
|
||||||
|
|
Loading…
Reference in a new issue