DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: [SOLVED VIA WORK AROUND] Get warnings from SMHI to text  (Read 7,078 times)

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 22
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.
SMHI1.png

I will put the text togehter with my other scripts as shown in this picture.
smhi2.png
smhi3.png

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"

« Last Edit: June 25, 2021, 08:20 PM by user45454 »

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 732
    • Participated in NANY Challenge Three Times
    • Linux User
Re: IDEA: Get warnings from SMHI to text
« Reply #1 on: June 13, 2021, 11:41 PM »
I'm in! :)

user45454

  • Participant
  • Joined in 2010
  • *
  • Posts: 22
Re: IDEA: Get warnings from SMHI to text
« Reply #2 on: June 15, 2021, 10:59 PM »
I'm in! :)

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

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 732
    • Participated in NANY Challenge Three Times
    • Linux User
Re: IDEA: Get warnings from SMHI to text
« Reply #3 on: June 16, 2021, 02:08 PM »
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

  • Participant
  • Joined in 2010
  • *
  • Posts: 22
Re: [SOLVED VIA WORK AROUND] Get warnings from SMHI to text
« Reply #4 on: June 25, 2021, 08:24 PM »
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.

Original address: https://www.donationcoder.com/forum/index.php?topic=51482.0