Skip to content

Commit 5aa5a13

Browse files
committed
migliora l'estrazione dei dati da HTML per gestire casi null e aggiorna l'URL dei PDF
1 parent 4e7ee03 commit 5aa5a13

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

ondate-calore.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,38 @@ else
5454
<"${folder}"/processing/output.html scrape -be '//table/thead' | xq -r '.html.body.thead.tr.td[]."#text"' | paste -sd, >"${folder}"/processing/ondate-calore.csv
5555

5656
# estrai dati
57-
<"${folder}"/processing/output.html scrape -be '//table/tbody/tr' | xq -c '.html.body.tr[]|{name:.td[0].a."#text",prima:.td[1].span."@class",seconda:.td[2].span."@class",terza:.td[3].span."@class"}' | mlr --j2c cat | tail -n +2 >>"${folder}"/processing/ondate-calore.csv
57+
<"${folder}"/processing/output.html scrape -be '//table/tbody/tr' | \
58+
xq -c '.html.body.tr[] |
59+
{
60+
name: (
61+
if (.td[0].a."#text" != null) then .td[0].a."#text"
62+
elif (.td[0].span."#text" != null) then .td[0].span."#text"
63+
else null
64+
end
65+
),
66+
prima: .td[1].span."@class",
67+
seconda: .td[2].span."@class",
68+
terza: .td[3].span."@class"
69+
}' | \
70+
mlr --j2c cat | tail -n +2 >>"${folder}"/processing/ondate-calore.csv
5871

5972
# estrai URL PDF
60-
<"${folder}"/processing/output.html scrape -be '//table/tbody/tr' | xq -c '.html.body.tr[]|{name:.td[0].a."#text",URL:.td[0].a."@href"}' | mlr --j2c label citta,URL then put '$URL=sub($URL,"http:","https:")' >"${folder}"/data/ondate-calore_PDF.csv
73+
<"${folder}"/processing/output.html scrape -be '//table/tbody/tr' | \
74+
xq -c '.html.body.tr[] |
75+
{
76+
name: (
77+
if (.td[0].a."#text" != null) then .td[0].a."#text"
78+
elif (.td[0].span."#text" != null) then .td[0].span."#text"
79+
else null
80+
end
81+
),
82+
URL: (
83+
if (.td[0].a."@href" != null) then .td[0].a."@href"
84+
else ""
85+
end
86+
)
87+
}' | \
88+
mlr --j2c label citta,URL then put '$URL=sub($URL,"http:","https:")' >"${folder}"/data/ondate-calore_PDF.csv
6189

6290
# URL completo per i PDF
6391
mlr -I --csv put '$URL="https://www.salute.gov.it".$URL' "${folder}"/data/ondate-calore_PDF.csv

0 commit comments

Comments
 (0)