Add News widget and integrate NewsAPI for live updates

This commit is contained in:
2025-12-29 21:19:05 +01:00
parent d638a8ae97
commit 9b5afc3d7c
9 changed files with 260 additions and 38 deletions

View File

@@ -3,21 +3,22 @@ package openWeatherMap
import "time"
type CurrentWeather struct {
Base string `json:"base"`
Visibility int `json:"visibility"`
Dt int `json:"dt"`
Timezone int `json:"timezone"`
Id int `json:"id"`
Name string `json:"name"`
Cod int `json:"cod"`
Coordinates Coordinates `json:"coord"`
Weather []Weather `json:"weather"`
Wind Wind `json:"wind"`
Clouds Clouds `json:"clouds"`
Rain Rain `json:"rain"`
Snow Snow `json:"snow"`
Sys Sys `json:"sys"`
Main Main `json:"main"`
Base string `json:"base"`
Visibility int `json:"visibility"`
Dt int `json:"dt"`
Timezone int `json:"timezone"`
Id int `json:"id"`
Name string `json:"name"`
Cod int `json:"cod"`
Coordinates Coordinates `json:"coord"`
Weather []Weather `json:"weather"`
Wind Wind `json:"wind"`
Clouds Clouds `json:"clouds"`
Rain Rain `json:"rain"`
Snow Snow `json:"snow"`
Sys Sys `json:"sys"`
Main Main `json:"main"`
ErrorMessage string
}
type Coordinates struct {

View File

@@ -4,7 +4,6 @@ import (
"ArinDash/config"
"encoding/json"
"io"
"log"
"net/http"
)
@@ -27,16 +26,22 @@ func FetchCurrentWeather() CurrentWeather {
req, err := http.NewRequest("GET", apiBaseURL+"?id="+cfg.OpenWeatherMap.LocationId+"&units=metric&lang=en&APPID="+cfg.OpenWeatherMap.ApiKey, nil)
if err != nil {
panic(err)
return CurrentWeather{
ErrorMessage: err.Error(),
}
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
return CurrentWeather{
ErrorMessage: err.Error(),
}
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
return CurrentWeather{
ErrorMessage: err.Error(),
}
}
err = json.Unmarshal(respBody, currentWeather)