DonationCoder.com Software > Post New Requests Here
[SOLVED VIA WORK AROUND] Get warnings from SMHI to text
(1/1)
user45454:
On this page the Swedish weather service is presenting weather warnings.
https://www.smhi.se/vader/varningar-och-risker/varningar#ws=wpt-a,proxy=wpt-a,district=none,page=wpt-warning-alla
(I could not find an API to get the information from).
I want to be able to run something like this and get the respons in plain text, and be able to send the output to a text file.
C:\> SMHIvarning.exe https://www.smhi.se/vader/varningar-och-risker/varningar#ws=wpt-a,proxy=wpt-a,district=035,page=wpt-warning-alla
"Inga varningar i Västmanlands län"
Or change to this that at the time of writing have a forrest fire warning
C:\> SMHIvarning.exe https://www.smhi.se/vader/varningar-och-risker/varningar#ws=wpt-a,proxy=wpt-a,district=017,page=wpt-warning-alla
"RISK SKOGSBRAND Kronobergs län, västra delen"
Or this that at the time of writing have a class one storm warning
C:\> SMHIvarning.exe https://www.smhi.se/vader/varningar-och-risker/varningar#ws=wpt-a,proxy=wpt-a,district=041,page=wpt-warning-alla
"VARNING KLASS 1 KULING Bottenviken"
Notice that the "district" in the url changes
Picture also provided to give information.
[SOLVED VIA WORK AROUND] Get warnings from SMHI to text
I will put the text togehter with my other scripts as shown in this picture.
[SOLVED VIA WORK AROUND] Get warnings from SMHI to text
[SOLVED VIA WORK AROUND] Get warnings from SMHI to text
With the output from C:\> SMHIvarning.exe https://www.smhi.se/vader/varningar-och-risker/varningar#ws=wpt-a,proxy=wpt-a,district=035,page=wpt-warning-alla > SMHIvastmanland.txt
i will use this "code" this is the way most of the output in above picture is created.
<code>
Echo |set /p=Varningar:
Type SMHIvastmanland.txt
</code>
Translations:
"Inga varningar i Västmanlands län" = "No warnings in Västmanlands län"
VARNING KLASS 1 KULING = "Warning class 1 gale"
RISK SKOGSBRAND "Risk Forest fire"
publicdomain:
I'm in! :)
user45454:
I'm in! :)
-publicdomain (June 13, 2021, 06:41 PM)
--- End quote ---
I found an API - https://opendata-download-warnings.smhi.se/api/version/2/messages.xml
Using Cygwin and below code.
<code>
Curl https://opendata-download-warnings.smhi.se/api/version/2/messages.xml > eldrisk1.txt
if DIFF -s eldrisk1.txt eldrisk1b.txt; then exit;
fi
cat eldrisk1.txt | egrep -i "<(text)>" | sed -e 's/<[^>]*>//g' -e 's/^[ \t]*//g' > eldrisk2.txt
if test -s eldrisk2.txt; then
iconv -f UTF-8 -t ISO-8859-15 eldrisk2.txt > eldrisk3.txt
else
echo "Ingen eldvarning utfärdad" > eldrisk3.txt
fi
cp eldrisk1.txt eldrisk1b.txt
</code>
This gives me
"Risken för bränder i skog och mark är stor eller mycket stor på flera håll i Götaland, Sörmland och Hälsingland"
(It says "Risk of fires in forest and ground is big or very big in several places in Götaland, Sörmland and Hälsingland)
There is another API with more info here: https://opendata-download-warnings.smhi.se/api/version/2/alerts.xml
publicdomain:
Thanks for the extended reply with alternative API.
I'm finishing some programs for community release right now + exploring these APIs for yours :Thmbsup:
Stay tuned!
Vic
user45454:
I managed to get this solved via the API and a bit of Cygwin.
Feel free to continue the work, but for me im happy with the result as I have it.
Navigation
[0] Message Index
Go to full version