mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-09 06:00:52 -05:00
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func advancedMenu(app *Application) {
|
|
|
|
var option string
|
|
|
|
// Menu loop
|
|
for option != "0" {
|
|
|
|
fmt.Print("\nAdvanced Menu\n-------------\n\n")
|
|
|
|
fmt.Printf("1. Change units (Default: imperial; Current: %s)\n", app.Config.Units)
|
|
fmt.Println("2. Enter precise location")
|
|
fmt.Println("3. Get historical data")
|
|
fmt.Print("0. Back\n\n")
|
|
|
|
// Read user input
|
|
reader := bufio.NewReader(os.Stdin)
|
|
input, err := reader.ReadString('\n')
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
option = strings.TrimSuffix(input, "\n")
|
|
|
|
// Check user input
|
|
if option == "1" {
|
|
current := app.Config.Units
|
|
if current == "imperial" {
|
|
app.Config.Units = "metric"
|
|
} else {
|
|
app.Config.Units = "imperial"
|
|
}
|
|
fmt.Printf("\nChanged units from %s to %s...\n\n", current, app.Config.Units)
|
|
} else if option == "2" {
|
|
|
|
// Loop to validate location entered
|
|
var validLoc bool
|
|
for !validLoc {
|
|
getPreciseLocation(app)
|
|
getCurrent(app)
|
|
|
|
if app.Forecast.Main.Temp != 0.00 {
|
|
validLoc = true
|
|
} else {
|
|
fmt.Println("I couldn't get any information for that location.")
|
|
fmt.Println("Are you sure the coordinates are valid?")
|
|
}
|
|
}
|
|
printWeather(app)
|
|
app.Forecast.Main.Temp = 0.00
|
|
|
|
} else if option == "3" {
|
|
var validLoc bool
|
|
for !validLoc {
|
|
getPreciseLocation(app)
|
|
getDate(app)
|
|
getHistoricalData(app.Client, app)
|
|
|
|
if app.Forecast.Main.Temp != 0.00 {
|
|
validLoc = true
|
|
} else {
|
|
fmt.Println("I couldn't get any information for that location.")
|
|
fmt.Println("Are you sure the coordinates are valid?")
|
|
}
|
|
}
|
|
printWeather(app)
|
|
app.Forecast.Main.Temp = 0.00
|
|
}
|
|
}
|
|
}
|