mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-21 12:43:09 -05:00
Added history.go
This commit is contained in:
parent
583e89e76c
commit
cdf1cb0971
1 changed files with 70 additions and 0 deletions
70
cmd/history.go
Normal file
70
cmd/history.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
pb "codeberg.org/andcscott/weather-cli/proto"
|
||||
)
|
||||
|
||||
func getDate(app *Application) (int32, int32, int32) {
|
||||
|
||||
var year, month, day int32
|
||||
|
||||
fmt.Print("Enter 4-digit year: ")
|
||||
|
||||
_, err := fmt.Scanf("%d", &year)
|
||||
if err != nil {
|
||||
fmt.Println("Invalid year")
|
||||
}
|
||||
|
||||
fmt.Print("Enter month (1-12): ")
|
||||
_, err = fmt.Scanf("%d", &month)
|
||||
if err != nil {
|
||||
fmt.Println("Invalid year")
|
||||
}
|
||||
|
||||
fmt.Print("Enter day (1-31): ")
|
||||
_, err = fmt.Scanf("%d", &day)
|
||||
if err != nil {
|
||||
fmt.Println("Invalid year")
|
||||
}
|
||||
return year, month, day
|
||||
}
|
||||
|
||||
func getUnixTime(c pb.RouteGuideClient) int32 {
|
||||
|
||||
var year, month, day int32
|
||||
|
||||
res, err := c.GetUnixTime(context.Background(), &pb.Date{
|
||||
Year: year,
|
||||
Month: month,
|
||||
Day: day,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting Unix time: %v\n", err)
|
||||
}
|
||||
return res.Unixtime
|
||||
}
|
||||
|
||||
func getHistorical(c pb.RouteGuideClient) {
|
||||
|
||||
var lat, lon, year, month, day int32
|
||||
|
||||
res, err := c.GetHistoricalData(context.Background(), &pb.LocationDate{
|
||||
Latitude: lat,
|
||||
Longitude: lon,
|
||||
Year: year,
|
||||
Month: month,
|
||||
Day: day,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting historical data: %v", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(res.Data), &app.Forecast)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading data from server: %v", err)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue