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