1
0
Fork 0

air-resource.net support

main v0.14.0
Jordan Hotmann 2023-11-29 21:25:57 -07:00
parent 6a4c1fb88f
commit c8afc750cb
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
2 changed files with 230 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package airresourcenet
import (
"encoding/json"
"fmt"
"strings"
"code.jhot.me/jhot/hats/internal/util"
"github.com/go-resty/resty/v2"
)
type AirResourceNetClient struct {
restClient *resty.Client
SiteCode string
}
func New(site string) *AirResourceNetClient {
return &AirResourceNetClient{
restClient: resty.New().
SetBaseURL(fmt.Sprintf("https://www.air-resource.net/%s", strings.ToUpper(site))),
SiteCode: site,
}
}
func (c *AirResourceNetClient) GetAirQualityData() (AirQualityData, error) {
var data AirQualityData
// Can't use .SetResult because the content type is text/plain
resp, err := util.CheckSuccess(c.restClient.R().Get(fmt.Sprintf("%sdatajson.txt", c.SiteCode)))
if err != nil {
return data, err
}
err = json.Unmarshal(resp.Body(), &data)
return data, err
}

View File

@ -0,0 +1,196 @@
package airresourcenet
type AirQualityData struct {
Version string `json:"version"`
Created string `json:"created"`
Name string `json:"name"`
State string `json:"state"`
Datadate string `json:"datadate"`
CurrentOzone8 string `json:"currentOzone8"`
CurrentOzone8AQI string `json:"currentOzone8AQI"`
CurrentOzone8AQIcolor string `json:"currentOzone8AQIcolor"`
CurrentOzone8AQItext string `json:"currentOzone8AQItext"`
CurrentOzoneNowcast string `json:"currentOzoneNowcast"`
CurrentOzoneNowcastAQI string `json:"currentOzoneNowcastAQI"`
CurrentOzoneNowcastAQIcolor string `json:"currentOzoneNowcastAQIcolor"`
CurrentOzoneNowcastAQItext string `json:"currentOzoneNowcastAQItext"`
CurrentPM25 string `json:"currentPM25"`
CurrentPM25AQI string `json:"currentPM25AQI"`
CurrentPM25AQIcolor string `json:"currentPM25AQIcolor"`
CurrentPM25AQItext string `json:"currentPM25AQItext"`
CurrentPM2524 string `json:"currentPM2524"`
CurrentPM2524AQI string `json:"currentPM2524AQI"`
CurrentPM2524AQIcolor string `json:"currentPM2524AQIcolor"`
CurrentPM2524AQItext string `json:"currentPM2524AQItext"`
CurrentPM25Nowcast string `json:"currentPM25Nowcast"`
CurrentPM25NowcastAQI string `json:"currentPM25NowcastAQI"`
CurrentPM25NowcastAQIcolor string `json:"currentPM25NowcastAQIcolor"`
CurrentPM25NowcastAQItext string `json:"currentPM25NowcastAQItext"`
CurrentPM1024 string `json:"currentPM1024"`
CurrentPM1024AQI string `json:"currentPM1024AQI"`
CurrentPM1024AQIcolor string `json:"currentPM1024AQIcolor"`
CurrentPM1024AQItext string `json:"currentPM1024AQItext"`
CurrentPM10Nowcast string `json:"currentPM10Nowcast"`
CurrentPM10NowcastAQI string `json:"currentPM10NowcastAQI"`
CurrentPM10NowcastAQIcolor string `json:"currentPM10NowcastAQIcolor"`
CurrentPM10NowcastAQItext string `json:"currentPM10NowcastAQItext"`
CurrentVisibility string `json:"currentVisibility"`
CurrentVisibilityAQI string `json:"currentVisibilityAQI"`
CurrentVisibilityAQIcolor string `json:"currentVisibilityAQIcolor"`
CurrentVisibilityAQItext string `json:"currentVisibilityAQItext"`
Locations []struct {
Name string `json:"name"`
Datadate string `json:"datadate"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
Elevation string `json:"elevation"`
Agency string `json:"agency"`
CurrentO3AQImax string `json:"currentO3AQImax,omitempty"`
CurrentO3AQIcolormax string `json:"currentO3AQIcolormax,omitempty"`
CurrentO3AQItextmax string `json:"currentO3AQItextmax,omitempty"`
Ozone struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Current8 string `json:"current8"`
CurrentNowcast string `json:"currentNowcast"`
Current8AQI string `json:"current8AQI"`
Current8AQIcolor string `json:"current8AQIcolor"`
Current8AQItext string `json:"current8AQItext"`
CurrentNowcastAQI string `json:"currentNowcastAQI"`
CurrentNowcastAQIcolor string `json:"currentNowcastAQIcolor"`
CurrentNowcastAQItext string `json:"currentNowcastAQItext"`
Data []int `json:"data"`
Data8 []int `json:"data8"`
Data8AQI []int `json:"data8AQI"`
DataNowcast []int `json:"dataNowcast"`
DataNowcastAQI []int `json:"dataNowcastAQI"`
} `json:"ozone,omitempty"`
AirTemperature struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Data []int `json:"data"`
} `json:"airTemperature,omitempty"`
WindSpeed struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Data []int `json:"data"`
} `json:"windSpeed,omitempty"`
WindDirection struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Data []int `json:"data"`
} `json:"windDirection,omitempty"`
Dummyparameter struct {
} `json:"dummyparameter"`
CurrentPMAQImax string `json:"currentPMAQImax,omitempty"`
CurrentPMAQIcolormax string `json:"currentPMAQIcolormax,omitempty"`
CurrentPMAQItextmax string `json:"currentPMAQItextmax,omitempty"`
Pm25 struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Current24 string `json:"current24"`
CurrentNowcast string `json:"currentNowcast"`
CurrentAQI string `json:"currentAQI"`
CurrentAQIcolor string `json:"currentAQIcolor"`
CurrentAQItext string `json:"currentAQItext"`
Current24AQI string `json:"current24AQI"`
Current24AQIcolor string `json:"current24AQIcolor"`
Current24AQItext string `json:"current24AQItext"`
CurrentNowcastAQI string `json:"currentNowcastAQI"`
CurrentNowcastAQIcolor string `json:"currentNowcastAQIcolor"`
CurrentNowcastAQItext string `json:"currentNowcastAQItext"`
Data []float64 `json:"data"`
Data24 []float64 `json:"data24"`
DataNowcast []float64 `json:"dataNowcast"`
DataAQI []int `json:"dataAQI"`
Data24AQI []int `json:"data24AQI"`
DataNowcastAQI []int `json:"dataNowcastAQI"`
} `json:"pm25,omitempty"`
Pm10 struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current24 string `json:"current24"`
CurrentNowcast string `json:"currentNowcast"`
Current24AQI string `json:"current24AQI"`
Current24AQIcolor string `json:"current24AQIcolor"`
Current24AQItext string `json:"current24AQItext"`
CurrentNowcastAQI string `json:"currentNowcastAQI"`
CurrentNowcastAQIcolor string `json:"currentNowcastAQIcolor"`
CurrentNowcastAQItext string `json:"currentNowcastAQItext"`
Data []float64 `json:"data"`
Data24 []float64 `json:"data24"`
DataNowcast []float64 `json:"dataNowcast"`
DataAQI []int `json:"dataAQI"`
Data24AQI []int `json:"data24AQI"`
DataNowcastAQI []int `json:"dataNowcastAQI"`
} `json:"pm10,omitempty"`
RelativeHumidity struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Data []int `json:"data"`
} `json:"relativeHumidity,omitempty"`
Precipitation struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Data []float64 `json:"data"`
} `json:"precipitation,omitempty"`
Et struct {
Display string `json:"display"`
Units string `json:"units"`
UnitsMetric string `json:"unitsMetric"`
UnitsMobile string `json:"unitsMobile"`
UnitsMetricMobile string `json:"unitsMetricMobile"`
MetricMultiplier string `json:"metricMultiplier"`
MetricOffset string `json:"metricOffset"`
Current string `json:"current"`
Data []float64 `json:"data"`
} `json:"et,omitempty"`
} `json:"locations"`
}