From 848cc6d61af04affe13f555aba93c21e6f7e15d9 Mon Sep 17 00:00:00 2001 From: Oscar Romeu Date: Sun, 5 Dec 2021 08:50:22 +0100 Subject: [PATCH] Added opendata operations --- README.md | 9 - estacions.go | 3 +- examples/influxdb/.env | 1 + examples/influxdb/config.yml | 13 +- examples/influxdb/go.sum | 15 -- examples/influxdb/main.go | 415 ++++++++--------------------------- go.mod | 4 +- go.sum | 36 --- mesurades.go | 2 +- meteocat.go | 313 ++------------------------ soda.go => opendata.go | 13 +- types.go | 291 ++++++++++++++++++++++++ 12 files changed, 420 insertions(+), 695 deletions(-) rename soda.go => opendata.go (80%) create mode 100644 types.go diff --git a/README.md b/README.md index 71dd22c..61eb50b 100644 --- a/README.md +++ b/README.md @@ -77,19 +77,10 @@ at [https://apidocs.meteocat.gencat.cat/documentacio/](https://apidocs.meteocat. ## TODO - [ ] Add trace request latency (DNSLookup, TCP Connection and so on) -- [ ] Add example to ingest data on Elasticsearch and visualize it on Kibana - [ ] Add example to insert data on Influxdb and visualize on Grafana Dashboard -- [ ] Add CLI features - [ ] Add support for the following API operations: - [x] Mesurades - [ ] Predicció - - [ ] Representatives - - [ ] Estacions - - [ ] Estadistics - - [ ] Càlcul multivariable - - [ ] Xarxa de Detecció de Descàrregues Elèctriques - - [ ] Referència - - [ ] Quotes - [ ] Full code coverage ## Bug Tracker diff --git a/estacions.go b/estacions.go index 0c1f0fd..df3a11b 100644 --- a/estacions.go +++ b/estacions.go @@ -98,7 +98,8 @@ func (e *Estacions) StationsAll(p *Parameters) error { return err } defer resp.Body.Close() - if sFlag == true { + //if sFlag == true { + if sFlag { if err = json.NewDecoder(resp.Body).Decode(&e.MetadadesEstacions); err != nil { return err } diff --git a/examples/influxdb/.env b/examples/influxdb/.env index e9d2a91..315fc9c 100644 --- a/examples/influxdb/.env +++ b/examples/influxdb/.env @@ -8,3 +8,4 @@ export INFLUX_USERNAME=admin export INFLUX_PASSWORD=admin export LOG_DEBUG=true export EXTRA_TAGS=group:my_group1 +export DOCKER_BUILDKIT=1 \ No newline at end of file diff --git a/examples/influxdb/config.yml b/examples/influxdb/config.yml index 2abb7ec..658bfc9 100644 --- a/examples/influxdb/config.yml +++ b/examples/influxdb/config.yml @@ -1,13 +1,18 @@ general: - meteocat_api_key: "my_apikey" - meteocat_codi_estacio: "" + meteocat_api_key: "uVCjZoDF7P3i6pCfRh1aI9YoQxFX6eRr1cjHypzs" + meteocat_codi_estacio: + - D5 + - X2 + - X4 + - X8 + - Y7 meteocat_codi_variable: "" database: - influx_server: "localhost" + influx_server: "192.168.1.69" influx_port: "8086" influx_bucket: "meteocat-testing" influx_measurement: "meteocat_all_by_station" influx_org: "Testing" - influx_token: "my_token" + influx_token: "5dYxum3y8db1ZZ4uCYkEjpt4C0AIqJ8oVwLW6IJcQ6O1h5olYMDv9GJewEHiLF6FjCQnqTDjrS-90ZLwFCLQBg==" diff --git a/examples/influxdb/go.sum b/examples/influxdb/go.sum index 712d214..0355143 100644 --- a/examples/influxdb/go.sum +++ b/examples/influxdb/go.sum @@ -36,14 +36,12 @@ github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deepmap/oapi-codegen v1.3.13 h1:9HKGCsdJqE4dnrQ8VerFS0/1ZOJPmAhN+g8xgp8y3K4= github.com/deepmap/oapi-codegen v1.3.13/go.mod h1:WAmG5dWY8/PYHt4vKxlt90NsbHMAOCiteYKZMiIRfOo= github.com/deepmap/oapi-codegen v1.5.1 h1:Xx8/OynzWhQeKFWr182hg6Ja2evS1gcqdja7qMn05yU= github.com/deepmap/oapi-codegen v1.5.1/go.mod h1:Eb1vtV3f58zvm37CJV4UAQ1bECb0fgAVvTdonC1ftJg= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= @@ -112,7 +110,6 @@ github.com/ilyakaznacheev/cleanenv v1.2.5/go.mod h1:/i3yhzwZ3s7hacNERGFwvlhwXMDc github.com/influxdata/influxdb-client-go/v2 v2.2.2 h1:O0CGIuIwQafvAxttAJ/VqMKfbWWn2Mt8rbOmaM2Zj4w= github.com/influxdata/influxdb-client-go/v2 v2.2.2/go.mod h1:fa/d1lAdUHxuc1jedx30ZfNG573oQTQmUni3N6pcW+0= github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU= github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/influxdata/line-protocol v0.0.0-20210219174132-3da7e03c5204 h1:CqG2IFRzE72d4gCVDnmkL3Xr/quhGF7sKfmyR7ZwK3k= github.com/influxdata/line-protocol v0.0.0-20210219174132-3da7e03c5204/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= @@ -128,19 +125,16 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/echo/v4 v4.1.17/go.mod h1:Tn2yRQL/UclUalpb5rPdXDevbkJ+lp/2svdyFBg6CHQ= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= -github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls= github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= @@ -151,7 +145,6 @@ github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIG github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -214,13 +207,11 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -279,7 +270,6 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191112182307-2180aed22343 h1:00ohfJ4K98s3m6BGUoBd8nyfp4Yl0GoIKvw5abItTjI= golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -315,7 +305,6 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 h1:Z991aAXPjz0tLnj74pVXW3eWJ5lHMIBvbRfMq4M2jHA= golang.org/x/sys v0.0.0-20201118182958-a01c418693c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -372,7 +361,6 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -383,12 +371,10 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -396,7 +382,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24 h1:sreVOrDp0/ezb0CHKVek/l7YwpxPJqv+jT3izfSphA4= olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw= olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 h1:slmdOY3vp8a7KQbHkL+FLbvbkgMqmXojpFUO/jENuqQ= olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw= diff --git a/examples/influxdb/main.go b/examples/influxdb/main.go index db87f1e..dd09390 100644 --- a/examples/influxdb/main.go +++ b/examples/influxdb/main.go @@ -1,315 +1,55 @@ package main import ( + "encoding/json" "flag" "fmt" "github.com/ilyakaznacheev/cleanenv" client "github.com/influxdata/influxdb-client-go/v2" "github.com/oscaromeu/meteocat" "github.com/sirupsen/logrus" + "net/http" "os" "strconv" "time" ) -// CodisEstacions holds all stations in ope state to be used -var CodisEstacions = map[string]string{ - "CC": "Orís", - "CD": "la Seu d'Urgell - Bellestar", - "CE": "els Hostalets de Pierola", - "CG": "Molló - Fabert", - "CI": "Sant Pau de Segúries", - "CJ": "Organyà", - "CL": "Sant Salvador de Guardiola", - "CP": "Sant Romà d'Abella", - "CQ": "Vilanova de Meià", - "CR": "la Quar", - "CT": "el Pont de Suert", - "CU": "Vielha", - "CW": "l'Espluga de Francolí", - "CY": "Muntanyola", - "C6": "Castellnou de Seana", - "C7": "Tàrrega", - "C8": "Cervera", - "C9": "Mas de Barberans", - "DB": "el Perelló", - "DF": "la Bisbal d'Empordà", - "DG": "Núria (1.971 m)", - "DI": "Font-rubí", - "DJ": "Banyoles", - "DK": "Torredembarra", - "DL": "Illa de Buda", - "DN": "Anglès", - "DO": "Castell d'Aro", - "DP": "Das - Aeròdrom", - "DQ": "Vila-rodona", - "D1": "Margalef", - "D2": "Vacarisses", - "D3": "Vallirana", - "D4": "Roses", - "D5": "Barcelona - Observatori Fabra", - "D6": "Portbou", - "D7": "Vinebre", - "D8": "Horta de Sant Joan", - "D9": "el Vendrell", - "H1": "Òdena", - "J5": "Pantà de Darnius - Boadella", - "KE": "Pantà de Sau", - "KP": "Fogars de la Selva", - "KX": "la Roca del Vallès - ETAP Cardedeu", - "MQ": "Cardona", - "MR": "Pantà de Siurana", - "MS": "Castellar de n'Hug - el Clot del Moro", - "MV": "Guixers - Valls", - "MW": "Navès", - "M6": "Sant Joan de les Abadesses", - "UA": "l'Ametlla de Mar", - "UB": "la Tallada d'Empordà", - "UC": "Monells", - "UE": "Torroella de Montgrí", - "UF": "PN del Garraf - el Rascler", - "UG": "Viladecans", - "UH": "el Montmell", - "UI": "Gisclareny", - "UJ": "Santa Coloma de Queralt", - "UK": "Sant Pere de Ribes - PN del Garraf", - "UM": "la Granadella", - "UN": "Cassà de la Selva", - "UO": "Fornells de la Selva", - "UP": "Cabrils", - "UQ": "Dosrius - PN Montnegre Corredor", - "US": "Alcanar", - "UU": "Amposta", - "UW": "els Alfacs", - "UX": "Ulldecona - els Valentins", - "UY": "Os de Balaguer - el Monestir d'Avellanes", - "U1": "Cabanes", - "U2": "Sant Pere Pescador", - "U3": "Sant Martí Sarroca", - "U4": "Castellnou de Bages", - "U6": "Vinyols i els Arcs", - "U7": "Aldover", - "U9": "l'Aldea", - "VA": "Ascó", - "VB": "Benissanet", - "VC": "Pantà de Riba-roja", - "VD": "el Canós", - "VE": "Aitona", - "VH": "Gimenells", - "VK": "Raimat", - "VM": "Vilanova de Segrià", - "VN": "Vilobí d'Onyar", - "VO": "Lladurs", - "VP": "Pinós", - "VQ": "Constantí", - "VS": "Lac Redon (2.247 m)", - "VU": "Rellinars", - "VV": "Sant Llorenç Savall", - "VX": "Tagamanent - PN del Montseny", - "VY": "Nulles", - "VZ": "Espolla", - "V1": "Vallfogona de Balaguer", - "V3": "Gurb", - "V4": "Montesquiu", - "V5": "Perafita", - "V8": "el Poal", - "WA": "Oliola", - "WB": "Albesa", - "WC": "Golmés", - "WD": "Batea", - "WE": "Vilanova del Vallès", - "WG": "Algerri", - "WI": "Maials", - "WJ": "el Masroig", - "WK": "Alfarràs", - "WL": "Sant Martí de Riucorb", - "WM": "Santuari de Queralt", - "WN": "Montserrat - Sant Dimes", - "WO": "la Bisbal del Penedès", - "WP": "Canaletes", - "WQ": "Montsec d'Ares (1.572 m)", - "WR": "Torroja del Priorat", - "WS": "Viladrau", - "WT": "Malgrat de Mar", - "WU": "Badalona - Museu", - "WV": "Guardiola de Berguedà", - "WW": "Artés", - "WX": "Camarasa", - "WY": "Sant Sadurní d'Anoia", - "WZ": "Cunit", - "W1": "Castelló d'Empúries", - "W4": "la Granada", - "W5": "Oliana", - "W8": "Blancafort", - "W9": "la Vall d'en Bas", - "XA": "la Panadella", - "XB": "la Llacuna", - "XC": "Castellbisbal", - "XD": "Ulldemolins", - "XE": "Tarragona - Complex Educatiu", - "XF": "Sabadell - Parc Agrari", - "XG": "Parets del Vallès", - "XH": "Sort", - "XI": "Mollerussa", - "XJ": "Girona", - "XK": "Puig Sesolles (1.668 m)", - "XL": "el Prat de Llobregat", - "XM": "els Alamús", - "XN": "Seròs", - "XO": "Vic", - "XP": "Gandesa", - "XQ": "Tremp", - "XR": "Prades", - "XS": "Santa Coloma de Farners", - "XT": "Solsona", - "XU": "Canyelles", - "XV": "Sant Cugat del Vallès - CAR", - "XX": "Tornabous", - "XY": "Alcarràs", - "XZ": "Torroella de Fluvià", - "X1": "Falset", - "X2": "Barcelona - Zoo", - "X3": "Alguaire", - "X4": "Barcelona - el Raval", - "X5": "PN dels Ports", - "X6": "Baldomar", - "X7": "Torres de Segre", - "X8": "Barcelona - Zona Universitària", - "X9": "Caldes de Montbui", - "YA": "Puigcerdà", - "YB": "Olot", - "YC": "la Pobla de Segur", - "YD": "les Borges Blanques", - "YE": "Massoteres", - "YF": "Mont-roig del Camp", - "YG": "Tírvia", - "YH": "Pujalt", - "YJ": "Lleida - la Femosa", - "YK": "Terrassa", - "YL": "Riudecanyes", - "YM": "Granollers", - "Y4": "Alinyà", - "Y5": "Navata", - "Y6": "Tivissa", - "Y7": "Port de Barcelona - Bocana Sud", - "ZB": "Salòria (2.451 m)", - "ZC": "Ulldeter (2.410 m)", - "ZD": "la Tosa d'Alp 2500", - "Z1": "Bonaigua (2.266 m)", - "Z2": "Boí (2.535 m)", - "Z3": "Malniu (2.230 m)", - "Z5": "Certascan (2.400 m)", - "Z6": "Sasseuva (2.228 m)", - "Z7": "Espot (2.519 m)", - "Z8": "el Port del Comte (2.316 m)", - "Z9": "Cadí Nord (2.143 m) - Prat d'Aguiló", -} - -// CodisVariables holds all the measurements performed by the weather stations. Note that not all the stations -// measures all the variables. To see which measurements a station does check the method MeasurementMetadataAllByStation -var CodisVariables = map[string]string{ - "1": "Pressió atmosfèrica màxima", - "2": "Pressió atmosfèrica mínima", - "3": "Humitat relativa màxima", - "X4": "Temperatura màxima de subsòl a 5 cm", - "5": "Temperatura mínima de subsòl a 5 cm", - "6": "TDR màxima a 10 cm", - "7": "TDR mínima a 10 cm", - "8": "Desviació estàndard de la irradiància neta", - "9": "Irradiància reflectida", - "10": "Irradiància fotosintèticament activa (PAR)", - "11": "Temperatura de supefície", - "12": "Temperatura màxima de superfície", - "13": "Temperatura mínima de superfície", - "14": "Temperatura de subsòl a 40 cm", - "16": "Nivell evaporímetre", - "20": "Velocitat del vent a 10 m (vec.)", - "21": "Direcció del vent a 10 m (m. u)", - "22": "Desviació est. de la direcció del vent a 10 m", - "23": "Velocitat del vent a 6 m (vec.)", - "24": "Direcció del vent a 6 m (m. u)", - "25": "Desviació est. de la direcció de vent a 6 m", - "26": "Velocitat del vent a 2 m (vec.)", - "27": "Direcció del vent a 2 m (m. u)", - "28": "Desviació est. de la direcció del vent a 2 m", - "30": "Velocitat del vent a 10 m (esc.)", - "31": "Direcció de vent 10 m (m. 1)", - "32": "Temperatura", - "33": "Humitat relativa", - "34": "Pressió atmosfèrica", - "35": "Precipitació", - "36": "Irradiància solar global", - "37": "Desviació est. de la irradiància solar global", - "38": "Gruix de neu a terra", - "39": "Radiació UV", - "40": "Temperatura màxima", - "42": "Temperatura mínima", - "44": "Humitat relativa mínima", - "46": "Velocitat del vent a 2 m (esc.)", - "47": "Direcció del vent a 2 m (m. 1)", - "48": "Velocitat del vent a 6 m (esc.)", - "49": "Direcció del vent a 6 m (m. 1)", - "50": "Ratxa màxima del vent a 10 m", - "51": "Direcció de la ratxa màxima del vent a 10 m", - "53": "Ratxa màxima del vent a 6 m", - "54": "Direcció de la ratxa màxima del vent a 6 m", - "56": "Ratxa màxima del vent a 2 m", - "57": "Direcció de la ratxa màxima del vent a 2 m", - "59": "Irradiància neta", - "60": "Temperatura de subsòl a 5 cm", - "61": "Temperatura de subsòl a 50 cm", - "62": "TDR a 10 cm", - "63": "TDR a 35 cm", - "64": "Humectació moll", - "65": "Humectació sec", - "66": "Humectació res", - "67": "Humectació moll 2", - "68": "Humectació sec 2", - "69": "Humectació res 2", - "70": "Precipitació acumulada", - "71": "Bateria", - "72": "Precipitació màxima en 1 minut", - "74": "Humitat del combustible forestal 1", - "75": "Temperatura del combustible forestal 1", - "76": "Humitat del combustible forestal 2", - "77": "Temperatura del combustible forestal 2", - "78": "Humitat del combustible forestal 3", - "79": "Temperatura del combustible forestal 3", - "80": "Temperatura de la neu 1", - "81": "Temperatura de la neu 2", - "82": "Temperatura de la neu 3", - "83": "Temperatura de la neu 4", - "84": "Temperatura de la neu 5", - "85": "Temperatura de la neu 6", - "86": "Temperatura de la neu 7", - "87": "Temperatura de la neu 8", - "88": "Quality number", - "89": "Temperatura del datalogger", - "90": "Altura màxima", - "91": "Període màxima", - "92": "Altura significant", - "93": "Període significant", - "94": "Altura mitjana", - "95": "Període mitjà", - "96": "Direcció del pic", - "97": "Temperatura superficial del mar", -} - var ( log = logrus.New() cfg Config - t time.Time + t time.Time Fields = make(map[string]interface{}) - Tags = make(map[string]string) + Tags = make(map[string]string) ) -const layout = "2006-01-02T15:04Z" +var ( + timeApiBaseURL = "https://www.timeapi.io/api/Time/current/zone?timeZone=Europe/Madrid" +) + +type Time struct { + Year int `json:"year"` + Month int `json:"month"` + Day int `json:"day"` + Hour int `json:"hour"` + Minute int `json:"minute"` + Seconds int `json:"seconds"` + MilliSeconds int `json:"milliSeconds"` + DateTime string `json:"dateTime"` + Date string `json:"date"` + Time string `json:"time"` + TimeZone string `json:"timeZone"` + DayOfWeek string `json:"dayOfWeek"` + DstActive bool `json:"dstActive"` +} type General struct { - ApiKey string `yaml:"meteocat_api_key" env:"METEOCAT_API_KEY" env-description:"Meteocat Api Key"` + ApiKey string `yaml:"meteocat_api_key" env:"METEOCAT_API_KEY" env-description:"Meteocat Api Key"` + Estacio []string `yaml:"meteocat_codi_estacio" env:"METEOCAT_CODI_ESTACIO" env-description:"Meteocat Codi Estacio"` } +const layout = "2006-01-02T15:04Z" + type Database struct { InfluxServer string `yaml:"influx_server" env:"INFLUX_SERVER" env-description:"Influx (Host) Server Instance"` InfluxPort string `yaml:"influx_port" env:"INFLUX_PORT" env-description:"Influx Server Instance"` @@ -332,7 +72,6 @@ type Args struct { ConfigPath string } - func init() { customFormatter := new(logrus.TextFormatter) @@ -388,8 +127,33 @@ func InitDB(conf Config) (client.Client, error) { } -func main() { +func (t *Time) getTime() { + + url := timeApiBaseURL + method := "GET" + client := &http.Client{} + req, err := http.NewRequest(method, url, nil) + + if err != nil { + fmt.Println(err) + return + } + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer res.Body.Close() + + if err := json.NewDecoder(res.Body).Decode(&t); err != nil { + fmt.Println(err) + return + } + +} + +func main() { c, err := InitDB(cfg) if err != nil { @@ -397,55 +161,54 @@ func main() { os.Exit(1) } - d, err := meteocat.NewMesurades(cfg.ApiKey) - if err != nil { - log.Fatalln(err) - os.Exit(3) - } + var t Time + var Tags = make(map[string]string) - if meteocat.CheckAPIKeyExists(d.Key) == false { - fmt.Println("ApiKey is not set. ") - } + t.getTime() + d, _ := meteocat.NewOpenDataMesurades() - year, month, day := time.Now().Date() data := meteocat.Data{ - Any: strconv.Itoa(year), - Mes: "0" + strconv.Itoa(int(month)), - Dia: strconv.Itoa(day - 1), + Any: strconv.Itoa(t.Year), + Mes: strconv.Itoa(t.Month), + Dia: strconv.Itoa(t.Day), } - params, _ := meteocat.NewParameters( - meteocat.OptionCodiEstacio("UG"), - //meteocat.OptionCodiVariable("5"), + // timeDate := meteocat.TimeDate{ + // Hour: strconv.Itoa(t.Hour), + // Minute: strconv.Itoa(t.Minute), + // Seconds: "00", + // } + + timeDate := meteocat.TimeDate{ + Hour: "05", + Minute: "00", + Seconds: "00", + } + fmt.Println(data) + p, _ := meteocat.NewParameters( meteocat.OptionData(data), + meteocat.OptionTimeDate(timeDate), ) - d.MeasurementAllByStation(params) + d.OpenDataMeasurementAllByStation(p) writeAPI := c.WriteAPI(cfg.InfluxOrg, cfg.InfluxBucket) - for _, v := range d.Measurements { - Tags["codi_estacio"] = v.Codi - Tags["Estacio"] = CodisEstacions[v.Codi] - for _, lec := range v.Variables { - Tags["codi_variable"] = strconv.Itoa(lec.Codi) - Tags["Variable"] = CodisVariables[strconv.Itoa(lec.Codi)] - for _, l := range lec.Lectures { - t, _ = time.Parse(layout, l.Data) - Fields["valor"] = l.Valor - - p := client.NewPoint(cfg.InfluxMeasurement, - Tags, - Fields, - t) - // write point asynchronously - writeAPI.WritePoint(p) - } - } - // Flush writes - writeAPI.Flush() + for _, v := range d.OpenData { + Tags["codi_estacio"] = v.CodiEstacio + Tags["nom_estacio"] = meteocat.CodisEstacions[v.CodiEstacio] + Tags["codi_variable"] = v.CodiVariable + Tags["nom_variable"] = meteocat.CodisVariables[v.CodiVariable] + t, _ = time.Parse(layout, data.Any, data.Mes, data.Dia) + Fields["valor"] = l.Valor + p := client.NewPoint(cfg.InfluxMeasurement, + Tags, + Fields, fmt.Sprintf("?data_lectura=%s-%s-%sT%s:%s:%s", p.Any, p.Mes, p.Dia, p.Hour, p.Minute, p.Seconds)) + // write point asynchronously + writeAPI.WritePoint(p) } - + // Flush writes + writeAPI.Flush() // always close client at the end defer c.Close() diff --git a/go.mod b/go.mod index f726c2a..6442c43 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,6 @@ go 1.13 require ( github.com/fatih/color v1.9.0 github.com/go-co-op/gocron v0.5.0 - github.com/ilyakaznacheev/cleanenv v1.2.5 - github.com/influxdata/influxdb-client-go/v2 v2.2.2 - github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab github.com/kelseyhightower/envconfig v1.4.0 github.com/mattn/go-colorable v0.1.7 // indirect github.com/pkg/errors v0.9.1 @@ -16,5 +13,6 @@ require ( github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.6.1 // indirect golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 // indirect + gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect ) diff --git a/go.sum b/go.sum index bf13f15..28c99b8 100644 --- a/go.sum +++ b/go.sum @@ -31,12 +31,9 @@ github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deepmap/oapi-codegen v1.3.13 h1:9HKGCsdJqE4dnrQ8VerFS0/1ZOJPmAhN+g8xgp8y3K4= -github.com/deepmap/oapi-codegen v1.3.13/go.mod h1:WAmG5dWY8/PYHt4vKxlt90NsbHMAOCiteYKZMiIRfOo= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= @@ -44,9 +41,7 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/getkin/kin-openapi v0.13.0/go.mod h1:WGRs2ZMM1Q8LR1QBEwUxC6RJEfaBcD0s+pcEVXFuAjw= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-co-op/gocron v0.5.0 h1:QBxhIsODdq6u9+Cu3JehdhznE2IzuEokOddpLnxVrtg= github.com/go-co-op/gocron v0.5.0/go.mod h1:6Btk4lVj3bnFAgbVfr76W8impTyhYrEi1pV5Pt4Tp/M= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -64,7 +59,6 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -102,16 +96,6 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/ilyakaznacheev/cleanenv v1.2.5 h1:/SlcF9GaIvefWqFJzsccGG/NJdoaAwb7Mm7ImzhO3DM= -github.com/ilyakaznacheev/cleanenv v1.2.5/go.mod h1:/i3yhzwZ3s7hacNERGFwvlhwXMDcaqwIzmayEhbRplk= -github.com/influxdata/influxdb-client-go/v2 v2.2.2 h1:O0CGIuIwQafvAxttAJ/VqMKfbWWn2Mt8rbOmaM2Zj4w= -github.com/influxdata/influxdb-client-go/v2 v2.2.2/go.mod h1:fa/d1lAdUHxuc1jedx30ZfNG573oQTQmUni3N6pcW+0= -github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab h1:HqW4xhhynfjrtEiiSGcQUd6vrK23iMam1FO8rI7mwig= -github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU= -github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= -github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= -github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -129,20 +113,14 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= -github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -210,15 +188,11 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= -github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -231,8 +205,6 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -265,8 +237,6 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191112182307-2180aed22343 h1:00ohfJ4K98s3m6BGUoBd8nyfp4Yl0GoIKvw5abItTjI= -golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -289,10 +259,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 h1:Z991aAXPjz0tLnj74pVXW3eWJ5lHMIBvbRfMq4M2jHA= @@ -320,7 +287,6 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -366,6 +332,4 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24 h1:sreVOrDp0/ezb0CHKVek/l7YwpxPJqv+jT3izfSphA4= -olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/mesurades.go b/mesurades.go index c66f230..1f550d3 100644 --- a/mesurades.go +++ b/mesurades.go @@ -210,6 +210,7 @@ func (m *Mesurades) MeasurementLast(p *Parameters) error { return err } + req.Header.Add("X-Api-Key", m.Key) resp, err := m.client.Do(req) @@ -370,7 +371,6 @@ func (m *Mesurades) MeasurementMetadataUnique(p *Parameters) error { } req.Header.Add("X-Api-Key", m.Key) - resp, err := m.client.Do(req) if err != nil { diff --git a/meteocat.go b/meteocat.go index 0e0da08..101acde 100644 --- a/meteocat.go +++ b/meteocat.go @@ -21,301 +21,11 @@ var ( baseURL = "https://api.meteo.cat/xema/v1%s" //baseURL="http://localhost:3000%s" openDataURL = "https://analisi.transparenciacatalunya.cat/resource/nzvn-apee.json%s" - url string // helper variable to hold url values - sFlag bool // helper variable to check where to handle JSON that varies between an array or a single item + url string // helper variable to hold url values + sFlag bool // helper variable to check where to handle JSON that varies between an array or a single item ) -// CodisEstat holds all the status that a station can have -var CodisEstat = map[string]string{ - "ope": "Operativa", // Operational - "des": "Desmantellada", // Dismantled - "bte": "Baixa temporal", // Not operational temporary -} - -// CodisEstacions holds all stations in ope state to be used -var CodisEstacions = map[string]string{ - "CC": "Orís", - "CD": "la Seu d'Urgell - Bellestar", - "CE": "els Hostalets de Pierola", - "CG": "Molló - Fabert", - "CI": "Sant Pau de Segúries", - "CJ": "Organyà", - "CL": "Sant Salvador de Guardiola", - "CP": "Sant Romà d'Abella", - "CQ": "Vilanova de Meià", - "CR": "la Quar", - "CT": "el Pont de Suert", - "CU": "Vielha", - "CW": "l'Espluga de Francolí", - "CY": "Muntanyola", - "C6": "Castellnou de Seana", - "C7": "Tàrrega", - "C8": "Cervera", - "C9": "Mas de Barberans", - "DB": "el Perelló", - "DF": "la Bisbal d'Empordà", - "DG": "Núria (1.971 m)", - "DI": "Font-rubí", - "DJ": "Banyoles", - "DK": "Torredembarra", - "DL": "Illa de Buda", - "DN": "Anglès", - "DO": "Castell d'Aro", - "DP": "Das - Aeròdrom", - "DQ": "Vila-rodona", - "D1": "Margalef", - "D2": "Vacarisses", - "D3": "Vallirana", - "D4": "Roses", - "D5": "Barcelona - Observatori Fabra", - "D6": "Portbou", - "D7": "Vinebre", - "D8": "Horta de Sant Joan", - "D9": "el Vendrell", - "H1": "Òdena", - "J5": "Pantà de Darnius - Boadella", - "KE": "Pantà de Sau", - "KP": "Fogars de la Selva", - "KX": "la Roca del Vallès - ETAP Cardedeu", - "MQ": "Cardona", - "MR": "Pantà de Siurana", - "MS": "Castellar de n'Hug - el Clot del Moro", - "MV": "Guixers - Valls", - "MW": "Navès", - "M6": "Sant Joan de les Abadesses", - "UA": "l'Ametlla de Mar", - "UB": "la Tallada d'Empordà", - "UC": "Monells", - "UE": "Torroella de Montgrí", - "UF": "PN del Garraf - el Rascler", - "UG": "Viladecans", - "UH": "el Montmell", - "UI": "Gisclareny", - "UJ": "Santa Coloma de Queralt", - "UK": "Sant Pere de Ribes - PN del Garraf", - "UM": "la Granadella", - "UN": "Cassà de la Selva", - "UO": "Fornells de la Selva", - "UP": "Cabrils", - "UQ": "Dosrius - PN Montnegre Corredor", - "US": "Alcanar", - "UU": "Amposta", - "UW": "els Alfacs", - "UX": "Ulldecona - els Valentins", - "UY": "Os de Balaguer - el Monestir d'Avellanes", - "U1": "Cabanes", - "U2": "Sant Pere Pescador", - "U3": "Sant Martí Sarroca", - "U4": "Castellnou de Bages", - "U6": "Vinyols i els Arcs", - "U7": "Aldover", - "U9": "l'Aldea", - "VA": "Ascó", - "VB": "Benissanet", - "VC": "Pantà de Riba-roja", - "VD": "el Canós", - "VE": "Aitona", - "VH": "Gimenells", - "VK": "Raimat", - "VM": "Vilanova de Segrià", - "VN": "Vilobí d'Onyar", - "VO": "Lladurs", - "VP": "Pinós", - "VQ": "Constantí", - "VS": "Lac Redon (2.247 m)", - "VU": "Rellinars", - "VV": "Sant Llorenç Savall", - "VX": "Tagamanent - PN del Montseny", - "VY": "Nulles", - "VZ": "Espolla", - "V1": "Vallfogona de Balaguer", - "V3": "Gurb", - "V4": "Montesquiu", - "V5": "Perafita", - "V8": "el Poal", - "WA": "Oliola", - "WB": "Albesa", - "WC": "Golmés", - "WD": "Batea", - "WE": "Vilanova del Vallès", - "WG": "Algerri", - "WI": "Maials", - "WJ": "el Masroig", - "WK": "Alfarràs", - "WL": "Sant Martí de Riucorb", - "WM": "Santuari de Queralt", - "WN": "Montserrat - Sant Dimes", - "WO": "la Bisbal del Penedès", - "WP": "Canaletes", - "WQ": "Montsec d'Ares (1.572 m)", - "WR": "Torroja del Priorat", - "WS": "Viladrau", - "WT": "Malgrat de Mar", - "WU": "Badalona - Museu", - "WV": "Guardiola de Berguedà", - "WW": "Artés", - "WX": "Camarasa", - "WY": "Sant Sadurní d'Anoia", - "WZ": "Cunit", - "W1": "Castelló d'Empúries", - "W4": "la Granada", - "W5": "Oliana", - "W8": "Blancafort", - "W9": "la Vall d'en Bas", - "XA": "la Panadella", - "XB": "la Llacuna", - "XC": "Castellbisbal", - "XD": "Ulldemolins", - "XE": "Tarragona - Complex Educatiu", - "XF": "Sabadell - Parc Agrari", - "XG": "Parets del Vallès", - "XH": "Sort", - "XI": "Mollerussa", - "XJ": "Girona", - "XK": "Puig Sesolles (1.668 m)", - "XL": "el Prat de Llobregat", - "XM": "els Alamús", - "XN": "Seròs", - "XO": "Vic", - "XP": "Gandesa", - "XQ": "Tremp", - "XR": "Prades", - "XS": "Santa Coloma de Farners", - "XT": "Solsona", - "XU": "Canyelles", - "XV": "Sant Cugat del Vallès - CAR", - "XX": "Tornabous", - "XY": "Alcarràs", - "XZ": "Torroella de Fluvià", - "X1": "Falset", - "X2": "Barcelona - Zoo", - "X3": "Alguaire", - "X4": "Barcelona - el Raval", - "X5": "PN dels Ports", - "X6": "Baldomar", - "X7": "Torres de Segre", - "X8": "Barcelona - Zona Universitària", - "X9": "Caldes de Montbui", - "YA": "Puigcerdà", - "YB": "Olot", - "YC": "la Pobla de Segur", - "YD": "les Borges Blanques", - "YE": "Massoteres", - "YF": "Mont-roig del Camp", - "YG": "Tírvia", - "YH": "Pujalt", - "YJ": "Lleida - la Femosa", - "YK": "Terrassa", - "YL": "Riudecanyes", - "YM": "Granollers", - "Y4": "Alinyà", - "Y5": "Navata", - "Y6": "Tivissa", - "Y7": "Port de Barcelona - Bocana Sud", - "ZB": "Salòria (2.451 m)", - "ZC": "Ulldeter (2.410 m)", - "ZD": "la Tosa d'Alp 2500", - "Z1": "Bonaigua (2.266 m)", - "Z2": "Boí (2.535 m)", - "Z3": "Malniu (2.230 m)", - "Z5": "Certascan (2.400 m)", - "Z6": "Sasseuva (2.228 m)", - "Z7": "Espot (2.519 m)", - "Z8": "el Port del Comte (2.316 m)", - "Z9": "Cadí Nord (2.143 m) - Prat d'Aguiló", -} - -// CodisVariables holds all the measurements performed by the weather stations. Note that not all the stations -// measures all the variables. To see which measurements a station does check the method MeasurementMetadataAllByStation -var CodisVariables = map[string]string{ - "1": "Pressió atmosfèrica màxima", - "2": "Pressió atmosfèrica mínima", - "3": "Humitat relativa màxima", - "X4": "Temperatura màxima de subsòl a 5 cm", - "5": "Temperatura mínima de subsòl a 5 cm", - "6": "TDR màxima a 10 cm", - "7": "TDR mínima a 10 cm", - "8": "Desviació estàndard de la irradiància neta", - "9": "Irradiància reflectida", - "10": "Irradiància fotosintèticament activa (PAR)", - "11": "Temperatura de supefície", - "12": "Temperatura màxima de superfície", - "13": "Temperatura mínima de superfície", - "14": "Temperatura de subsòl a 40 cm", - "16": "Nivell evaporímetre", - "20": "Velocitat del vent a 10 m (vec.)", - "21": "Direcció del vent a 10 m (m. u)", - "22": "Desviació est. de la direcció del vent a 10 m", - "23": "Velocitat del vent a 6 m (vec.)", - "24": "Direcció del vent a 6 m (m. u)", - "25": "Desviació est. de la direcció de vent a 6 m", - "26": "Velocitat del vent a 2 m (vec.)", - "27": "Direcció del vent a 2 m (m. u)", - "28": "Desviació est. de la direcció del vent a 2 m", - "30": "Velocitat del vent a 10 m (esc.)", - "31": "Direcció de vent 10 m (m. 1)", - "32": "Temperatura", - "33": "Humitat relativa", - "34": "Pressió atmosfèrica", - "35": "Precipitació", - "36": "Irradiància solar global", - "37": "Desviació est. de la irradiància solar global", - "38": "Gruix de neu a terra", - "39": "Radiació UV", - "40": "Temperatura màxima", - "42": "Temperatura mínima", - "44": "Humitat relativa mínima", - "46": "Velocitat del vent a 2 m (esc.)", - "47": "Direcció del vent a 2 m (m. 1)", - "48": "Velocitat del vent a 6 m (esc.)", - "49": "Direcció del vent a 6 m (m. 1)", - "50": "Ratxa màxima del vent a 10 m", - "51": "Direcció de la ratxa màxima del vent a 10 m", - "53": "Ratxa màxima del vent a 6 m", - "54": "Direcció de la ratxa màxima del vent a 6 m", - "56": "Ratxa màxima del vent a 2 m", - "57": "Direcció de la ratxa màxima del vent a 2 m", - "59": "Irradiància neta", - "60": "Temperatura de subsòl a 5 cm", - "61": "Temperatura de subsòl a 50 cm", - "62": "TDR a 10 cm", - "63": "TDR a 35 cm", - "64": "Humectació moll", - "65": "Humectació sec", - "66": "Humectació res", - "67": "Humectació moll 2", - "68": "Humectació sec 2", - "69": "Humectació res 2", - "70": "Precipitació acumulada", - "71": "Bateria", - "72": "Precipitació màxima en 1 minut", - "74": "Humitat del combustible forestal 1", - "75": "Temperatura del combustible forestal 1", - "76": "Humitat del combustible forestal 2", - "77": "Temperatura del combustible forestal 2", - "78": "Humitat del combustible forestal 3", - "79": "Temperatura del combustible forestal 3", - "80": "Temperatura de la neu 1", - "81": "Temperatura de la neu 2", - "82": "Temperatura de la neu 3", - "83": "Temperatura de la neu 4", - "84": "Temperatura de la neu 5", - "85": "Temperatura de la neu 6", - "86": "Temperatura de la neu 7", - "87": "Temperatura de la neu 8", - "88": "Quality number", - "89": "Temperatura del datalogger", - "90": "Altura màxima", - "91": "Període màxima", - "92": "Altura significant", - "93": "Període significant", - "94": "Altura mitjana", - "95": "Període mitjà", - "96": "Direcció del pic", - "97": "Temperatura superficial del mar", -} - // Config will hold default settings type Config struct { APIKey string // API Key for connecting to the OWM @@ -329,12 +39,20 @@ type Data struct { Dia string } +type TimeDate struct { + Hour string + Minute string + Seconds string + Milliseconds string +} + // Parameters holds all the options to be passed in to the methods type Parameters struct { codiEstacio string // should reference a key in the CodisEstacions map codiVariable string // should reference a key in the CodisVariables map codiEstat string // should reference a key in the CodisEstat map Data + TimeDate } // NewParameters generates a new Parameters config. @@ -392,6 +110,17 @@ func OptionData(d Data) func(p *Parameters) error { } } +// Option TimeData is a helper function to set up the value of Timedate to be passed in Parameters struct +func OptionTimeDate(d TimeDate) func(p *Parameters) error { + return func(p *Parameters) error { + p.Hour = d.Hour + p.Minute = d.Minute + p.Seconds = d.Seconds + p.Milliseconds = d.Milliseconds + return nil + } +} + // APIError returned on failed API calls. type APIError struct { Message string `json:"message"` diff --git a/soda.go b/opendata.go similarity index 80% rename from soda.go rename to opendata.go index d7e0854..8e44fea 100644 --- a/soda.go +++ b/opendata.go @@ -6,7 +6,7 @@ import ( "net/http" ) -type OpenData[]struct { +type OpenData []struct { ID string `json:"id"` CodiEstacio string `json:"codi_estacio"` CodiVariable string `json:"codi_variable"` @@ -21,21 +21,21 @@ type OpenDataMeasurements struct { *Settings } - // NewMesurades returns a new MesuradesData pointer with the supplied parameters func NewOpenDataMesurades() (*OpenDataMeasurements, error) { c := &OpenDataMeasurements{ Settings: NewSettings(), } - return c, nil } func (s *OpenDataMeasurements) OpenDataMeasurementAllByStation(p *Parameters) error { - - req, err := http.NewRequest("GET", fmt.Sprintf(openDataURL, fmt.Sprintf("?data_lectura=%s-%s-%sT06:00:00", p.Any, p.Mes, p.Dia)), nil) + req, err := http.NewRequest("GET", fmt.Sprintf( + openDataURL, fmt.Sprintf("?data_lectura=%s-%s-%sT%s:%s:%s", + p.Any, p.Mes, p.Dia, p.Hour, p.Minute, p.Seconds)), nil) // 2021-12-05T04:30:00.000 + fmt.Println(req) if err != nil { return err } @@ -44,7 +44,6 @@ func (s *OpenDataMeasurements) OpenDataMeasurementAllByStation(p *Parameters) er resp, err := s.client.Do(req) - if err != nil { fmt.Println(err) return err @@ -57,5 +56,3 @@ func (s *OpenDataMeasurements) OpenDataMeasurementAllByStation(p *Parameters) er return nil } - - diff --git a/types.go b/types.go new file mode 100644 index 0000000..9ab4e86 --- /dev/null +++ b/types.go @@ -0,0 +1,291 @@ +package meteocat + +// CodisEstat holds all the status that a station can have +var CodisEstat = map[string]string{ + "ope": "Operativa", // Operational + "des": "Desmantellada", // Dismantled + "bte": "Baixa temporal", // Not operational temporary +} + +// CodisEstacions holds all stations in ope state to be used +var CodisEstacions = map[string]string{ + "CC": "Orís", + "CD": "la Seu d'Urgell - Bellestar", + "CE": "els Hostalets de Pierola", + "CG": "Molló - Fabert", + "CI": "Sant Pau de Segúries", + "CJ": "Organyà", + "CL": "Sant Salvador de Guardiola", + "CP": "Sant Romà d'Abella", + "CQ": "Vilanova de Meià", + "CR": "la Quar", + "CT": "el Pont de Suert", + "CU": "Vielha", + "CW": "l'Espluga de Francolí", + "CY": "Muntanyola", + "C6": "Castellnou de Seana", + "C7": "Tàrrega", + "C8": "Cervera", + "C9": "Mas de Barberans", + "DB": "el Perelló", + "DF": "la Bisbal d'Empordà", + "DG": "Núria (1.971 m)", + "DI": "Font-rubí", + "DJ": "Banyoles", + "DK": "Torredembarra", + "DL": "Illa de Buda", + "DN": "Anglès", + "DO": "Castell d'Aro", + "DP": "Das - Aeròdrom", + "DQ": "Vila-rodona", + "D1": "Margalef", + "D2": "Vacarisses", + "D3": "Vallirana", + "D4": "Roses", + "D5": "Barcelona - Observatori Fabra", + "D6": "Portbou", + "D7": "Vinebre", + "D8": "Horta de Sant Joan", + "D9": "el Vendrell", + "H1": "Òdena", + "J5": "Pantà de Darnius - Boadella", + "KE": "Pantà de Sau", + "KP": "Fogars de la Selva", + "KX": "la Roca del Vallès - ETAP Cardedeu", + "MQ": "Cardona", + "MR": "Pantà de Siurana", + "MS": "Castellar de n'Hug - el Clot del Moro", + "MV": "Guixers - Valls", + "MW": "Navès", + "M6": "Sant Joan de les Abadesses", + "UA": "l'Ametlla de Mar", + "UB": "la Tallada d'Empordà", + "UC": "Monells", + "UE": "Torroella de Montgrí", + "UF": "PN del Garraf - el Rascler", + "UG": "Viladecans", + "UH": "el Montmell", + "UI": "Gisclareny", + "UJ": "Santa Coloma de Queralt", + "UK": "Sant Pere de Ribes - PN del Garraf", + "UM": "la Granadella", + "UN": "Cassà de la Selva", + "UO": "Fornells de la Selva", + "UP": "Cabrils", + "UQ": "Dosrius - PN Montnegre Corredor", + "US": "Alcanar", + "UU": "Amposta", + "UW": "els Alfacs", + "UX": "Ulldecona - els Valentins", + "UY": "Os de Balaguer - el Monestir d'Avellanes", + "U1": "Cabanes", + "U2": "Sant Pere Pescador", + "U3": "Sant Martí Sarroca", + "U4": "Castellnou de Bages", + "U6": "Vinyols i els Arcs", + "U7": "Aldover", + "U9": "l'Aldea", + "VA": "Ascó", + "VB": "Benissanet", + "VC": "Pantà de Riba-roja", + "VD": "el Canós", + "VE": "Aitona", + "VH": "Gimenells", + "VK": "Raimat", + "VM": "Vilanova de Segrià", + "VN": "Vilobí d'Onyar", + "VO": "Lladurs", + "VP": "Pinós", + "VQ": "Constantí", + "VS": "Lac Redon (2.247 m)", + "VU": "Rellinars", + "VV": "Sant Llorenç Savall", + "VX": "Tagamanent - PN del Montseny", + "VY": "Nulles", + "VZ": "Espolla", + "V1": "Vallfogona de Balaguer", + "V3": "Gurb", + "V4": "Montesquiu", + "V5": "Perafita", + "V8": "el Poal", + "WA": "Oliola", + "WB": "Albesa", + "WC": "Golmés", + "WD": "Batea", + "WE": "Vilanova del Vallès", + "WG": "Algerri", + "WI": "Maials", + "WJ": "el Masroig", + "WK": "Alfarràs", + "WL": "Sant Martí de Riucorb", + "WM": "Santuari de Queralt", + "WN": "Montserrat - Sant Dimes", + "WO": "la Bisbal del Penedès", + "WP": "Canaletes", + "WQ": "Montsec d'Ares (1.572 m)", + "WR": "Torroja del Priorat", + "WS": "Viladrau", + "WT": "Malgrat de Mar", + "WU": "Badalona - Museu", + "WV": "Guardiola de Berguedà", + "WW": "Artés", + "WX": "Camarasa", + "WY": "Sant Sadurní d'Anoia", + "WZ": "Cunit", + "W1": "Castelló d'Empúries", + "W4": "la Granada", + "W5": "Oliana", + "W8": "Blancafort", + "W9": "la Vall d'en Bas", + "XA": "la Panadella", + "XB": "la Llacuna", + "XC": "Castellbisbal", + "XD": "Ulldemolins", + "XE": "Tarragona - Complex Educatiu", + "XF": "Sabadell - Parc Agrari", + "XG": "Parets del Vallès", + "XH": "Sort", + "XI": "Mollerussa", + "XJ": "Girona", + "XK": "Puig Sesolles (1.668 m)", + "XL": "el Prat de Llobregat", + "XM": "els Alamús", + "XN": "Seròs", + "XO": "Vic", + "XP": "Gandesa", + "XQ": "Tremp", + "XR": "Prades", + "XS": "Santa Coloma de Farners", + "XT": "Solsona", + "XU": "Canyelles", + "XV": "Sant Cugat del Vallès - CAR", + "XX": "Tornabous", + "XY": "Alcarràs", + "XZ": "Torroella de Fluvià", + "X1": "Falset", + "X2": "Barcelona - Zoo", + "X3": "Alguaire", + "X4": "Barcelona - el Raval", + "X5": "PN dels Ports", + "X6": "Baldomar", + "X7": "Torres de Segre", + "X8": "Barcelona - Zona Universitària", + "X9": "Caldes de Montbui", + "YA": "Puigcerdà", + "YB": "Olot", + "YC": "la Pobla de Segur", + "YD": "les Borges Blanques", + "YE": "Massoteres", + "YF": "Mont-roig del Camp", + "YG": "Tírvia", + "YH": "Pujalt", + "YJ": "Lleida - la Femosa", + "YK": "Terrassa", + "YL": "Riudecanyes", + "YM": "Granollers", + "Y4": "Alinyà", + "Y5": "Navata", + "Y6": "Tivissa", + "Y7": "Port de Barcelona - Bocana Sud", + "ZB": "Salòria (2.451 m)", + "ZC": "Ulldeter (2.410 m)", + "ZD": "la Tosa d'Alp 2500", + "Z1": "Bonaigua (2.266 m)", + "Z2": "Boí (2.535 m)", + "Z3": "Malniu (2.230 m)", + "Z5": "Certascan (2.400 m)", + "Z6": "Sasseuva (2.228 m)", + "Z7": "Espot (2.519 m)", + "Z8": "el Port del Comte (2.316 m)", + "Z9": "Cadí Nord (2.143 m) - Prat d'Aguiló", +} + +// CodisVariables holds all the measurements performed by the weather stations. Note that not all the stations +// measures all the variables. To see which measurements a station does check the method MeasurementMetadataAllByStation +var CodisVariables = map[string]string{ + "1": "Pressió atmosfèrica màxima", + "2": "Pressió atmosfèrica mínima", + "3": "Humitat relativa màxima", + "X4": "Temperatura màxima de subsòl a 5 cm", + "5": "Temperatura mínima de subsòl a 5 cm", + "6": "TDR màxima a 10 cm", + "7": "TDR mínima a 10 cm", + "8": "Desviació estàndard de la irradiància neta", + "9": "Irradiància reflectida", + "10": "Irradiància fotosintèticament activa (PAR)", + "11": "Temperatura de supefície", + "12": "Temperatura màxima de superfície", + "13": "Temperatura mínima de superfície", + "14": "Temperatura de subsòl a 40 cm", + "16": "Nivell evaporímetre", + "20": "Velocitat del vent a 10 m (vec.)", + "21": "Direcció del vent a 10 m (m. u)", + "22": "Desviació est. de la direcció del vent a 10 m", + "23": "Velocitat del vent a 6 m (vec.)", + "24": "Direcció del vent a 6 m (m. u)", + "25": "Desviació est. de la direcció de vent a 6 m", + "26": "Velocitat del vent a 2 m (vec.)", + "27": "Direcció del vent a 2 m (m. u)", + "28": "Desviació est. de la direcció del vent a 2 m", + "30": "Velocitat del vent a 10 m (esc.)", + "31": "Direcció de vent 10 m (m. 1)", + "32": "Temperatura", + "33": "Humitat relativa", + "34": "Pressió atmosfèrica", + "35": "Precipitació", + "36": "Irradiància solar global", + "37": "Desviació est. de la irradiància solar global", + "38": "Gruix de neu a terra", + "39": "Radiació UV", + "40": "Temperatura màxima", + "42": "Temperatura mínima", + "44": "Humitat relativa mínima", + "46": "Velocitat del vent a 2 m (esc.)", + "47": "Direcció del vent a 2 m (m. 1)", + "48": "Velocitat del vent a 6 m (esc.)", + "49": "Direcció del vent a 6 m (m. 1)", + "50": "Ratxa màxima del vent a 10 m", + "51": "Direcció de la ratxa màxima del vent a 10 m", + "53": "Ratxa màxima del vent a 6 m", + "54": "Direcció de la ratxa màxima del vent a 6 m", + "56": "Ratxa màxima del vent a 2 m", + "57": "Direcció de la ratxa màxima del vent a 2 m", + "59": "Irradiància neta", + "60": "Temperatura de subsòl a 5 cm", + "61": "Temperatura de subsòl a 50 cm", + "62": "TDR a 10 cm", + "63": "TDR a 35 cm", + "64": "Humectació moll", + "65": "Humectació sec", + "66": "Humectació res", + "67": "Humectació moll 2", + "68": "Humectació sec 2", + "69": "Humectació res 2", + "70": "Precipitació acumulada", + "71": "Bateria", + "72": "Precipitació màxima en 1 minut", + "74": "Humitat del combustible forestal 1", + "75": "Temperatura del combustible forestal 1", + "76": "Humitat del combustible forestal 2", + "77": "Temperatura del combustible forestal 2", + "78": "Humitat del combustible forestal 3", + "79": "Temperatura del combustible forestal 3", + "80": "Temperatura de la neu 1", + "81": "Temperatura de la neu 2", + "82": "Temperatura de la neu 3", + "83": "Temperatura de la neu 4", + "84": "Temperatura de la neu 5", + "85": "Temperatura de la neu 6", + "86": "Temperatura de la neu 7", + "87": "Temperatura de la neu 8", + "88": "Quality number", + "89": "Temperatura del datalogger", + "90": "Altura màxima", + "91": "Període màxima", + "92": "Altura significant", + "93": "Període significant", + "94": "Altura mitjana", + "95": "Període mitjà", + "96": "Direcció del pic", + "97": "Temperatura superficial del mar", +}