mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-08 05:50:51 -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
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
// Load .env
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Read API_KEY from .env and create app
|
||||
cfg := config{
|
||||
Units: "imperial",
|
||||
ApiKey: os.Getenv("API_KEY"),
|
||||
|
@ -87,8 +68,7 @@ func main() {
|
|||
Version: version,
|
||||
}
|
||||
|
||||
var option string
|
||||
|
||||
// Display main menu
|
||||
fmt.Println("\n=====================================================")
|
||||
fmt.Printf("| Welcome to the OpenWeatherMap-gRPC Client! v%s |\n", app.Version)
|
||||
fmt.Println("=====================================================")
|
||||
|
@ -98,22 +78,23 @@ func main() {
|
|||
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")
|
||||
|
||||
var option string
|
||||
// Menu loop
|
||||
for option != "0" {
|
||||
|
||||
fmt.Print("\nMain Menu\n---------\n\n")
|
||||
|
||||
fmt.Println("1. Today's forecast (use current location, default)")
|
||||
fmt.Println("2. Advanced options (Change units, precise location, etc.)")
|
||||
fmt.Print("0. Exit\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" || option == "" {
|
||||
getLocation(&app)
|
||||
getCurrent(&app)
|
||||
|
|
Loading…
Reference in a new issue