Dutch local covid-19 figures

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
snuiter
Posts: 67
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Dutch local covid-19 figures

Post by snuiter »

Hi,
On the RIVM site there is a JSON file with information on the covid per town. I have tried several thing to read the JSON but I am not able to read it via dzVents. My knowledge on coding is lacking here. Any help is appreciated.

Here is the data: https://data.rivm.nl/covid-19/COVID-19_ ... atief.json

My idea was to filter based on the Municipality code : GMxxxx

0
Date_of_report "2020-03-13 10:00:00"
Municipality_code "GM0003"
Municipality_name "Appingedam"
Province "Groningen"
Total_reported 0
Hospital_admission 0
Deceased 0
1 {…}

Code: Select all

if (item.isHTTPResponse) then
    print("http response")
    if item.ok and item.isJSON then
        print("succesfull JSON response from RIVM")
        -- local json = domoticz.utils.fromJSON(item.data)
        -- local result_table = item.json.nodes
-- 		local tc = #json
		dz.log(item.statusCode)
		dz.log(item.headers)
		
-- 		test = item.data[1]
-- 		print(test)
		
        -- for i = 1, 100 do
        --     if json[i].Municipality_code == gemeente then
        --         print("gemeente gevonden")
        --         print(i)
        --     end
        -- end

This is not working at all, so I guess am I not able to read the attributes right in the JSON data.

Any suggestions?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dutch local covid-19 figures

Post by waaren »

snuiter wrote: Saturday 15 August 2020 22:45 On the RIVM site there is a JSON file with information on the covid per town. I have tried several thing to read the JSON but I am not able to read it via dzVents. My knowledge on coding is lacking here. Any help is appreciated.
Please find a suggested solution in dzVents in this post
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snuiter
Posts: 67
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Dutch local covid-19 figures

Post by snuiter »

Hi Waaren,
thanks for the great suggestion/script, I am able to follow what happens but not in specific detail. So I did some print of the commands and paste them on the commandline to see what happens.

- getURLcommand works fine and have the 10Mb file in the tmp folder
- jqCommand tried that but no output, the output file _Rotterdam stays empty
tried with sudo and chown from root to pi

all with no luck

I will have a look online at understanding the jq command beter

so this part of the total jqCommand delivers an scrolling output filtered on the city name

Code: Select all

jq ' .[] | select (.Municipality_name == "Rotterdam" )' /tmp/rivmDataCumulative 
but when this is piped into a file, then the file is empty

Code: Select all

| jq -s > /tmp/rivmData_Rotterdam 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dutch local covid-19 figures

Post by waaren »

snuiter wrote: Monday 17 August 2020 21:17 - jqCommand tried that but no output, the output file _Rotterdam stays empty when this is piped into a file, then the file is empty
Probably my mistake. I use jq 1.6 (Debian bullseye) and in that version the bug that redirecting output from stdout only works when make it implicit (using an extra dot) is fixed. In jq version 1.5 you need to include this dot so like

Code: Select all

jq ' .[] | select (.Municipality_name == "Rotterdam" )' /tmp/rivmDataCumulative | jq . -s >  /tmp/rivmData_Rotterdam
I have updated the posted script accordingly
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JeroenG
Posts: 27
Joined: Monday 06 January 2020 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 20231
Contact:

Re: Dutch local covid-19 figures

Post by JeroenG »

Hi Waaren,

Living in 'Alphen aan den Rijn', can't get the script working.

My guess it has to do with the spaces in city name, because 2 temp files are written with the name rivmData_Alphen and rivmTotal_Alphen (both without 'aan den Rijn'). This files remain empty. If I run the jq statement manually it produces data:


Code: Select all

/tmp $ jq '.[] | select (.Municipality_name == "Alphen aan den Rijn")' rivmDataCumulative | jq .[-1] -s
{
  "Date_of_report": "2020-08-18 10:00:00",
  "Municipality_code": "GM0484",
  "Municipality_name": "Alphen aan den Rijn",
  "Province": "Zuid-Holland",
  "Total_reported": 266,
  "Hospital_admission": 63,
  "Deceased": 25
}
/tmp $

Tried the following:

Add a local variable with city name with spaces replaced by underscore:

Code: Select all

local city = 'Alphen aan den Rijn' -- Change to one of the cities from above overview 
local city2 = 'Alphen_aan_den_Rijn' -- City name with spaces replaced by underscore 
Modified the temp file locations accordingly:

Code: Select all

local rivmFiltered = '/tmp/rivmData' .. '_' .. city2
local rivmTotal = '/tmp/rivmTotal' .. '_' .. city2
With this small adjustment the tempfiles are filled with the correct data. But still no date appears in my sensors :-(.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dutch local covid-19 figures

Post by waaren »

JeroenG wrote: Tuesday 18 August 2020 22:53 With this small adjustment the tempfiles are filled with the correct data. But still no date appears in my sensors :-(.
Will have a look but probably not before tomorrow.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest