Main project #1

Merged
raul merged 33 commits from testing into main 2024-06-14 07:49:34 +02:00
1 changed files with 22 additions and 19 deletions
Showing only changes of commit 281e194bc5 - Show all commits

View File

@ -1,11 +1,9 @@
package cmd
import (
"encoding/json"
"fmt"
xj "github.com/basgys/goxml2json"
"io"
"log"
"net/http"
"strings"
)
@ -16,6 +14,7 @@ type root struct {
Prediccion struct {
Dia []struct {
Fecha string `json:"-fecha"`
UV string `json:"uv_max"`
Temperatura struct {
Maxima string `json:"maxima"`
Minima string `json:"minima"`
@ -32,28 +31,32 @@ type root struct {
Hora string `json:"-hora"`
}
}
Humedad_Relativa struct {
Maxima string `json:"maxima"`
Minima string `json:"minima"`
}
}
}
} `json:"root"`
}
func client() {
jsonData, err := getJSON()
if err != nil {
log.Fatal(err)
}
textBytes := []byte(jsonData)
aemetRequest := root{}
err = json.Unmarshal(textBytes, &aemetRequest)
if err != nil {
log.Fatalf("Error occurred unmarshalling data: %v\n", err)
}
fmt.Println(aemetRequest.Base.Nombre)
fmt.Println(aemetRequest.Base.Prediccion.Dia[0].Fecha)
fmt.Printf("Temperatura máxima: %v°C\n", aemetRequest.Base.Prediccion.Dia[0].Temperatura.Maxima)
fmt.Printf("Temperatura mínima: %v°C\n", aemetRequest.Base.Prediccion.Dia[0].Temperatura.Minima)
}
// func client() {
// jsonData, err := getJSON()
// if err != nil {
// log.Fatal(err)
// }
// textBytes := []byte(jsonData)
// aemetRequest := root{}
// err = json.Unmarshal(textBytes, &aemetRequest)
// if err != nil {
// log.Fatalf("Error occurred unmarshalling data: %v\n", err)
// }
//
// fmt.Println(aemetRequest.Base.Nombre)
// fmt.Println(aemetRequest.Base.Prediccion.Dia[0].Fecha)
// fmt.Printf("Temperatura máxima: %v°C\n", aemetRequest.Base.Prediccion.Dia[0].Temperatura.Maxima)
// fmt.Printf("Temperatura mínima: %v°C\n", aemetRequest.Base.Prediccion.Dia[0].Temperatura.Minima)
// }
func getJSON() (s string, err error) {
client := &http.Client{}