2022-07-07 20:27:00 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-08-02 23:26:09 -04:00
|
|
|
func advancedMenu(app *Application) {
|
2022-07-07 20:27:00 -04:00
|
|
|
|
|
|
|
var option string
|
|
|
|
|
2022-07-26 22:20:04 -04:00
|
|
|
// Menu loop
|
2022-07-07 20:27:00 -04:00
|
|
|
for option != "0" {
|
|
|
|
|
|
|
|
fmt.Print("\nAdvanced Menu\n-------------\n\n")
|
|
|
|
|
2022-07-11 19:07:24 -04:00
|
|
|
fmt.Printf("1. Change units (Default: imperial; Current: %s)\n", app.Config.Units)
|
2022-07-07 20:27:00 -04:00
|
|
|
fmt.Println("2. Enter precise location")
|
2022-08-02 23:26:09 -04:00
|
|
|
fmt.Println("3. Get historical data")
|
2022-07-07 20:27:00 -04:00
|
|
|
fmt.Print("0. Back\n\n")
|
|
|
|
|
2022-07-26 22:20:04 -04:00
|
|
|
// Read user input
|
2022-07-07 20:27:00 -04:00
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
input, err := reader.ReadString('\n')
|
|
|
|
if err != nil {
|
2022-07-08 22:12:39 -04:00
|
|
|
log.Println(err)
|
2022-07-07 20:27:00 -04:00
|
|
|
}
|
|
|
|
option = strings.TrimSuffix(input, "\n")
|
|
|
|
|
2022-07-26 22:20:04 -04:00
|
|
|
// Check user input
|
2022-07-07 20:27:00 -04:00
|
|
|
if option == "1" {
|
2022-07-08 22:12:39 -04:00
|
|
|
current := app.Config.Units
|
|
|
|
if current == "imperial" {
|
|
|
|
app.Config.Units = "metric"
|
2022-07-07 23:43:16 -04:00
|
|
|
} else {
|
2022-07-08 22:12:39 -04:00
|
|
|
app.Config.Units = "imperial"
|
2022-07-07 23:43:16 -04:00
|
|
|
}
|
2022-07-08 22:12:39 -04:00
|
|
|
fmt.Printf("\nChanged units from %s to %s...\n\n", current, app.Config.Units)
|
2022-07-07 20:27:00 -04:00
|
|
|
} else if option == "2" {
|
2022-07-13 17:04:33 -04:00
|
|
|
|
2022-07-26 22:20:04 -04:00
|
|
|
// Loop to validate location entered
|
2022-07-13 17:04:33 -04:00
|
|
|
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?")
|
|
|
|
}
|
|
|
|
}
|
2022-08-02 23:26:09 -04:00
|
|
|
printWeather(app)
|
|
|
|
app.Forecast.Main.Temp = 0.00
|
|
|
|
|
|
|
|
} else if option == "3" {
|
|
|
|
var validLoc bool
|
|
|
|
for !validLoc {
|
|
|
|
getPreciseLocation(app)
|
|
|
|
getHistorical(app.Client)
|
|
|
|
}
|
2022-07-13 17:04:33 -04:00
|
|
|
|
2022-08-02 23:26:09 -04:00
|
|
|
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?")
|
|
|
|
}
|
2022-07-09 15:33:10 -04:00
|
|
|
printWeather(app)
|
2022-07-26 22:20:04 -04:00
|
|
|
app.Forecast.Main.Temp = 0.00
|
2022-07-07 20:27:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|