[[BrmMeteo]]
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

project:brmmeteo:start [2019/01/30 00:18]
sachy created
project:brmmeteo:start [2019/02/05 21:21] (current)
sachy progress
Line 3: Line 3:
 <code bash brmmeteo.sh>​ <code bash brmmeteo.sh>​
 #!/bin/bash #!/bin/bash
 +#
 +# $1 = output synop CSV file
 +# $2 = output HTML map
 +# $3 = output JSON file
 +#
  
 # https://​www.ogimet.com/​ultimos_synops2.php?​lang=en&​estado=Czec&​fmt=html&​Send=Send # https://​www.ogimet.com/​ultimos_synops2.php?​lang=en&​estado=Czec&​fmt=html&​Send=Send
Line 10: Line 15:
 # http://​www.weather.org.uk/​resource/​syn_code.htm # http://​www.weather.org.uk/​resource/​syn_code.htm
  
 +
 +# How far station is
 +function dalka()
 +{
 + local x=$(echo "​$3-$1"​ | bc)
 + local y=$(echo "​$4-$2"​ | bc)
 + echo "​sqrt((($3-$1)^2)+(($4-$2)^2))"​ | bc -l| sed -e '​s/​^\./​0./​g'​ -e '​s/​^-\./​-0./​g'​
 +}
 +
 +# Angle to another station
 +function uhel ()
 +{
 + local x=$(echo "​$3-$1"​ | bc)
 + local y=$(echo "​$4-$2"​ | bc)
 + echo "​$y/​sqrt(($x*$x)+($y*$y))"​ | bc -l| sed -e '​s/​^\./​0./​g'​ -e '​s/​^-\./​-0./​g'​
 +}
 +
 +# Return close points $1=stanice $2=CSV
 +function blizke()
 +{
 + local id=$(echo "​$1"​ |  awk -F', ' '​{print $4}' | grep -o -e'​[0-9]*'​)
 + local x=$(echo "​$1"​ | awk -F', ' '​{print $2}' | sed -e '​s/​.$//​g'​)
 + local y=$(echo "​$1"​ | awk -F', ' '​{print $3}' | sed -e '​s/​.$//​g'​)
 + local m=$(echo "​$1"​ | awk -F', ' '​{print $1}')
 +
 + local tab=""​
 +
 + while IFS=''​ read -r br || [[ -n "​$br"​ ]]; do
 + local rid=$(echo "​$br"​ |  awk -F', ' '​{print $4}' | grep -o -e'​[0-9]*'​)
 + if [[ "​$id"​ == "​$rid"​ ]]; then
 + continue;​
 + fi
 +
 + local rx=$(echo "​$br"​ | awk -F', ' '​{print $2}' | sed -e '​s/​.$//​g'​)
 + local ry=$(echo "​$br"​ | awk -F', ' '​{print $3}' | sed -e '​s/​.$//​g'​)
 + local rmm=$(echo "​$br"​ | awk -F', ' '​{print $1}')
 +
 + local rd=$(dalka "​$x"​ "​$y"​ "​$rx"​ "​$ry"​)
 +
 + tab+="​$rd $rid $m -> $rmm\n"​
 + done <<<​ $(echo "​$2"​)
 +
 + tab=$(echo -e "​$tab"​ | sort)
 + echo -e "​$tab"​
 +}
 +
 +
 +json="​var data='​{\"​version\":​\"​$(date --rfc-3339=seconds)\",​\"​stanice\":​["​
  
 #​syno=$(wget "​https://​www.ogimet.com/​cgi-bin/​getsynop?​begin=201901291800&​state=Cze"​ -O - > /dev/null 2>&​1 ​ #​syno=$(wget "​https://​www.ogimet.com/​cgi-bin/​getsynop?​begin=201901291800&​state=Cze"​ -O - > /dev/null 2>&​1 ​
  
-syno=$(cat /s/syno | cut -b 35- | sed -e 's/ /, /g' | sed -e '​s/​^11406/​Cheb,​ 50.05N, 12.24E, 11406/​g'​ -e '​s/​^11414/​Karlovy Vary, 50.12N, 12.55E, 11414/​g'​ -e '​s/​^11423/​Primda,​ 49.40N, 12.40E, 11423/​g'​ -e '​s/​^11438/​Tusimice,​ 50.23N, 13.20E, 11438/​g'​ -e '​s/​^11450/​Plzen-Mikolka, 49.46N, 13.23E, 11450/​g'​ -e '​s/​^11457/​Churanov,​ 49.04N, 13.37E, 11457/​g'​ -e '​s/​^11464/​Milesovka,​ 50.33N, 13.56E, 11464/​g'​ -e '​s/​^11487/​Kocelovice,​ 49.28N, 13.50E, 11487/​g'​ -e '​s/​^11502/​Usti n. Labem, 50.41N, 14.02E, 11502/​g'​ -e '​s/​^11509/​Doksany,​ 50.28N, 14.10E, 11509/​g'​ -e '​s/​^11518/​Praha-Ruzyne,​ 50.06N, 14.15E, 11518/​g'​ -e '​s/​^11520/​Praha-Libus,​ 50.01N, 14.27E, 11520/​g'​ -e '​s/​^11538/​Temelin,​ 49.12N, 14.20E, 11538/​g'​ -e '​s/​^11546/​C. Budejovice-Roznov, 48.57N, 14.28E, 11546/​g'​ -e '​s/​^11567/​Praha-Kbely,​ 50.07N, 14.32E, 11567/​g'​ -e '​s/​^11603/​Liberec,​ 50.46N, 15.01E, 11603/​g'​ -e '​s/​^11624/​Caslav,​ 49.56N, 15.23E, 11624/​g'​ -e '​s/​^11628/​Kramolin-Kosetice,​ 49.35N, 15.05E, 11628/​g'​ -e '​s/​^11636/​Kostelni Myslova, 49.09N, 15.26E, 11636/​g'​ -e '​s/​^11643/​Pec p. Snezkou, 50.40N, 15.45E, 11643/​g'​ -e '​s/​^11652/​Pardubice,​ 50.01N, 15.44E, 11652/​g'​ -e '​s/​^11653/​Snezka,​ 50.44N, 15.44E, 11653/​g'​ -e '​s/​^11659/​Pribyslav,​ 49.35N, 15.46E, 11659/​g'​ -e '​s/​^11669/​Polom,​ 50.21N, 16.19E, 11669/​g'​ -e '​s/​^11679/​Usti n. Orlici, 49.59N, 16.26E, 11679/​g'​ -e '​s/​^11683/​Svratouch,​ 49.44N, 16.02E, 11683/​g'​ -e '​s/​^11692/​Namest n. Oslavou, 49.10N, 16.08E, 11692/​g'​ -e '​s/​^11693/​Dukovany,​ 49.06N, 16.08E, 11693/​g'​ -e '​s/​^11698/​Kucharovice,​ 48.53N, 16.05E, 11698/​g'​ -e '​s/​^11710/​Luka,​ 49.39N, 16.05E, 11710/​g'​ -e '​s/​^11723/​Brno-Turany,​ 49.09N, 16.42E, 11723/​g'​ -e '​s/​^11730/​Serak,​ 50.11N, 17.07E, 11730/​g'​ -e '​s/​^11747/​Prostejov,​ 49.27N, 17.08E, 11747/​g'​ -e '​s/​^11766/​Cervena, 49.46N, 17.33E, 11766/​g'​ -e '​s/​^11774/​Holesov,​ 49.19N, 17.34E, 11774/​g'​ -e '​s/​^11782/​Ostrava-Mosnov,​ 49.01N, 18.07E, 11782/​g'​ -e '​s/​^11787/​Lysa hora, 49.33N, 18.27E, 11787/​g'​ -e '​s/​^11791/​Maruska Hostalkova, 49.21N, 17.49E, 11791/​g'​)+syno=$(cat /s/syno | cut -b 35- | sed -e 's/ /, /g' | sed -e '​s/​^11406/​Cheb,​ 50.0683N, 12.3913E, 11406/​g'​ -e '​s/​^11414/​Karlovy Vary, 50.2016N, 12.9139E, 11414/​g'​ -e '​s/​^11423/​Primda,​ 49.6694N, 12.6779E, 11423/​g'​ -e '​s/​^11438/​Tusimice,​ 50.3765N, 13.3279E, 11438/​g'​ -e '​s/​^11450/​Plzen-Mikulka, 49.7645N, 13.3787E, 11450/​g'​ -e '​s/​^11457/​Churanov,​ 49.0683N, 13.615E, 11457/​g'​ -e '​s/​^11464/​Milesovka,​ 50.5549N, 13.9306E, 11464/​g'​ -e '​s/​^11487/​Kocelovice,​ 49.4672N, 13.8385E, 11487/​g'​ -e '​s/​^11502/​Usti n. Labem, 50.6833N, 14.0410E, 11502/​g'​ -e '​s/​^11509/​Doksany,​ 50.4587N, 14.1699E, 11509/​g'​ -e '​s/​^11518/​Praha-Ruzyne,​ 50.1003N, 14.2555E, 11518/​g'​ -e '​s/​^11520/​Praha-Libus,​ 50.0077N, 14.4467E, 11520/​g'​ -e '​s/​^11538/​Temelin,​ 49.1975N, 14.3421E, 11538/​g'​ -e '​s/​^11546/​C. Budejovice, 48.9519N, 14.4697E, 11546/​g'​ -e '​s/​^11567/​Praha-Kbely,​ 50.1232N, 14.538E, 11567/​g'​ -e '​s/​^11603/​Liberec,​ 50.7697N, 15.0238E, 11603/​g'​ -e '​s/​^11624/​Caslav,​ 49.9407N, 15.3863E, 11624/​g'​ -e '​s/​^11628/​Kramolin-Kosetice,​ 49.5735N, 15.0803E, 11628/​g'​ -e '​s/​^11636/​Kostelni Myslova, 49.159N, 15.4391E, 11636/​g'​ -e '​s/​^11643/​Pec p. Snezkou, 50.6918N, 15.7287E, 11643/​g'​ -e '​s/​^11652/​Pardubice,​ 50.1580N, 15.7402E, 11652/​g'​ -e '​s/​^11653/​Snezka,​ 50.68N, 15.44E, 11653/​g'​ -e '​s/​^11659/​Pribyslav,​ 49.5825N, 15.7623E, 11659/​g'​ -e '​s/​^11669/​Polom,​ 50.3503N, 16.3221E, 11669/​g'​ -e '​s/​^11679/​Usti n. Orlici, 49.9801N, 16.4221E, 11679/​g'​ -e '​s/​^11683/​Svratouch,​ 49.735N, 16.0342E, 11683/​g'​ -e '​s/​^11692/​Namest n. Oslavou, 49.1708N, 16.1205E, 11692/​g'​ -e '​s/​^11693/​Dukovany,​ 49.0954N, 16.1344E, 11693/​g'​ -e '​s/​^11698/​Kucharovice,​ 48.8809N, 16.0852E, 11698/​g'​ -e '​s/​^11710/​Luka,​ 49.6522N, 16.9533E, 11710/​g'​ -e '​s/​^11723/​Brno-Turany,​ 49.1530N, 16.6888E, 11723/​g'​ -e '​s/​^11730/​Serak,​ 50.1874N, 17.1082E, 11730/​g'​ -e '​s/​^11747/​Prostejov,​ 49.4525N, 17.1347E, 11747/​g'​ -e '​s/​^11766/​Cervená u Libavé, 49.7770N, 17.5418E, 11766/​g'​ -e '​s/​^11774/​Holesov,​ 49.3205N, 17.5699E, 11774/​g'​ -e '​s/​^11782/​Ostrava-Mosnov,​ 49.6918N, 18.1126E, 11782/​g'​ -e '​s/​^11787/​Lysa hora, 49.5459N, 18.4473E, 11787/​g'​ -e '​s/​^11791/​Maruska Hostalkova, 49.3650N, 17.8284E, 11791/​g'​)
  
-#echo "​$syno"​+#echo "$syno" > "$1"
  
 while IFS=''​ read -r radek || [[ -n "​$radek"​ ]]; do while IFS=''​ read -r radek || [[ -n "​$radek"​ ]]; do
 +
 + blizke "​$radek"​ "​$syno"​
 + echo "​---"​
 +
  mesto=$(echo "​$radek"​ | grep -o -e '​^[^,​]*'​)  mesto=$(echo "​$radek"​ | grep -o -e '​^[^,​]*'​)
- gpsn=$(echo "​$radek"​ | awk -F', ' '​{print $2}'​) + gpsn=$(echo "​$radek"​ | awk -F', ' '​{print $2}'| sed -e '​s/​.$//​g') 
- gpse=$(echo "​$radek"​ | awk -F', ' '​{print $3}')+ gpse=$(echo "​$radek"​ | awk -F', ' '​{print $3}'| sed -e '​s/​.$//​g')
  mestoid=$(echo "​$radek"​ | awk -F', ' '​{print $4}')  mestoid=$(echo "​$radek"​ | awk -F', ' '​{print $4}')
  
Line 39: Line 96:
  ff=$(echo "​$radek"​ | awk -F', ' '​{print $6}' | cut -b 4-5)  ff=$(echo "​$radek"​ | awk -F', ' '​{print $6}' | cut -b 4-5)
  # rychlost vetru v m/s  # rychlost vetru v m/s
- ff=$(echo "​$ff*0.514"​ | bc | sed -e '​s/​^\./​0\./​g'​)+ ff=$(echo "0$ff*0.514"​ | bc | sed -e '​s/​^\./​0\./​g'​)
  #echo "$n $dd $ff"  #echo "$n $dd $ff"
  
  section1=$(echo "​$radek"​ | grep -o -P -e ' (1[0-9/​]{4},​ )?​(2[0-9/​]{4},​ )?​(3[0-9/​]{4},​ )?​(4[0-9/​]{4},​ )?​(5[0-9/​]{4},​ )?​(6[0-9/​]{4},​ )?​(7[0-9/​]{4},​ )?​(8[0-9/​]{4},​ )?​333,'​ | cut -c 2- | sed -e 's/, 333,//​g'​)  section1=$(echo "​$radek"​ | grep -o -P -e ' (1[0-9/​]{4},​ )?​(2[0-9/​]{4},​ )?​(3[0-9/​]{4},​ )?​(4[0-9/​]{4},​ )?​(5[0-9/​]{4},​ )?​(6[0-9/​]{4},​ )?​(7[0-9/​]{4},​ )?​(8[0-9/​]{4},​ )?​333,'​ | cut -c 2- | sed -e 's/, 333,//​g'​)
  
- s11sn=$(echo "​$section1"​ | grep -o -P -e '​1[0-9/​]{4}'​ | cut -b 2)+ # znamenko teploty (0=+; 1=-) 
 + s11sn=$(echo "​$section1"​ | grep -o -P -e '​1[0-9/​]{4}'​ | cut -b 2 | tr '​1'​ '​-'​ | tr '​0'​ '​+'​)
  # teplota v desetinach  # teplota v desetinach
  s11ttt=$(echo "​$section1"​ | grep -o -P -e '​1[0-9/​]{4}'​ | cut -b 3-5)  s11ttt=$(echo "​$section1"​ | grep -o -P -e '​1[0-9/​]{4}'​ | cut -b 3-5)
  # teplota v °C  # teplota v °C
- s11ttt=$(echo "​$s11ttt*0.1"​ | bc)+ s11ttt=$(echo "$s11sn 0 $s11ttt*0.1" ​| tr -d ' ' ​| bc) 
 + # rosny bod znamenko
  s12sn=$(echo "​$section1"​ | grep -o -P -e '​2[0-9/​]{4}'​ | cut -b 2)  s12sn=$(echo "​$section1"​ | grep -o -P -e '​2[0-9/​]{4}'​ | cut -b 2)
 + # rosny bod teplota °C
  s12ttt=$(echo "​$section1"​ | grep -o -P -e '​2[0-9/​]{4}'​ | cut -b 3-5)  s12ttt=$(echo "​$section1"​ | grep -o -P -e '​2[0-9/​]{4}'​ | cut -b 3-5)
- #s13sn=$(echo "​$section1"​ | grep -o -P -e '​3[0-9/​]{4}'​ | cut -b 2)+tlak v mBar (stary ale v CR asi pouzivany) 
 + s13tttt=$(echo "​$section1"​ | grep -o -P -e '​3[0-9/​]{4}'​ | cut -b 2-5) 
 + s13tttt=$(echo "​((0$s13tttt)*100)+101325"​ | bc)
  # tlak v mBar  # tlak v mBar
  s14pppp=$(echo "​$section1"​ | grep -o -P -e '​4[0-9/​]{4}'​ | cut -b 2-5)  s14pppp=$(echo "​$section1"​ | grep -o -P -e '​4[0-9/​]{4}'​ | cut -b 2-5)
  # tlak v Pa  # tlak v Pa
- s14pppp=$(echo "​(0$s14pppp*100)+101325"​ | bc)+ s14pppp=$(echo "​(0$s14pppp*0.1*100)+101325"​ | bc) 
 + # zmena tlaku +-
  s15a=$(echo "​$section1"​ | grep -o -P -e '​5[0-9/​]{4}'​ | cut -b 2)  s15a=$(echo "​$section1"​ | grep -o -P -e '​5[0-9/​]{4}'​ | cut -b 2)
 + # zmena tlaku v desetinach mBar/3h
  s15ppp=$(echo "​$section1"​ | grep -o -P -e '​5[0-9/​]{4}'​ | cut -b 3-5)  s15ppp=$(echo "​$section1"​ | grep -o -P -e '​5[0-9/​]{4}'​ | cut -b 3-5)
 + # srazky mm/6h
  s16rrr=$(echo "​$section1"​ | grep -o -P -e '​6[0-9/​]{4}'​ | cut -b 2-4)  s16rrr=$(echo "​$section1"​ | grep -o -P -e '​6[0-9/​]{4}'​ | cut -b 2-4)
  s16tr=$(echo "​$section1"​ | grep -o -P -e '​6[0-9/​]{4}'​ | cut -b 5)  s16tr=$(echo "​$section1"​ | grep -o -P -e '​6[0-9/​]{4}'​ | cut -b 5)
 + # aktualni pocasi
  s17ww=$(echo "​$section1"​ | grep -o -P -e '​7[0-9/​]{4}'​ | cut -b 2-3)  s17ww=$(echo "​$section1"​ | grep -o -P -e '​7[0-9/​]{4}'​ | cut -b 2-3)
 + # minule pocasi
  s17w1w2=$(echo "​$section1"​ | grep -o -P -e '​7[0-9/​]{4}'​ | cut -b 4-5)  s17w1w2=$(echo "​$section1"​ | grep -o -P -e '​7[0-9/​]{4}'​ | cut -b 4-5)
 + # oblacnost
  s18nh=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 2)  s18nh=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 2)
 + # ...nizka
  s18cl=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 3)  s18cl=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 3)
 + # ...stredni
  s18cm=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 4)  s18cm=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 4)
 + # ...vysoka
  s18ch=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 5)  s18ch=$(echo "​$section1"​ | grep -o -P -e '​8[0-9/​]{4}'​ | cut -b 5)
  
Line 105: Line 176:
  # VYPIS  # VYPIS
  
- echo "​$mesto ​  ​$gpsn,​$gpse ​  $ff m/s   ​$s11ttt °C   $s14pppp ​Pa";+ echo "​$radek"​ 
 + echo "​$mesto ​  ​$gpsn,​$gpse ​  $ff m/s   ​$s11ttt °C   $s13tttt ​Pa   $s16rrr mm/6h"; 
 + 
 + json+="​{"​ 
 + json+="​\"​station\":​\"​$mesto\","​ 
 + json+="​\"​gpse\":​\"​$gpse\","​ 
 + json+="​\"​gpsn\":​\"​$gpsn\","​ 
 + json+="​\"​wind\":​\"​$ff\","​ 
 + json+="​\"​temp\":​\"​$s11ttt\","​ 
 + json+="​\"​press\":​\"​$s13tttt\","​ 
 + json+="​\"​rain\":​\"​$s16rrr\","​ 
 + json+="​\"​raw\":​\"​$radek\""​ # posledni bez , 
 + json+="​},"​ 
 done <<<​ $(echo "​$syno"​) done <<<​ $(echo "​$syno"​)
 +
 +json+="​{}]}'"​
 +echo "​$json"​ | sed -e "​s/​^var data='//​g"​ -e "​s/'​$//​g"​ > "​$3"​
 +
 +
 +# STATIC
 +
 +js='<​script>'​
 +js+='​map = new OpenLayers.Map("​map"​);'​
 +js+='​map.addLayer(new OpenLayers.Layer.OSM());'​
 +js+='​epsg4326 =  new OpenLayers.Projection("​EPSG:​4326"​);'​ # WGS 1984 projection
 +js+='​projectTo = map.getProjectionObject();'​ # The map projection (Spherical Mercator)
 +js+='​var lonLat = new OpenLayers.LonLat(15.478,​ 49.817).transform(epsg4326,​ projectTo);'​
 +js+='​var zoom=8;'​
 +js+='​map.setCenter (lonLat, zoom);'​
 +js+="​$json"​
 +js+="</​script>"​
 +
 +html='<​!DOCTYPE html>'​
 +html+='<​html>'​
 +html+='<​head>'​
 +html+='<​meta http-equiv="​Content-Type"​ content="​text/​html;​ charset=utf-8">'​
 +html+='<​title>​BrmMeteo</​title>'​
 +html+='<​link rel="​stylesheet"​ href="​./​style.css"​ type="​text/​css">'​
 +html+='<​link rel="​favicon"​ href="​./​biohazard.svg">'​
 +html+='<​script src="​./​OpenLayers.js"></​script>'​
 +html+='</​head>'​
 +html+='<​body>'​
 +html+="<​h1 id='​title'>​BrmMeteo - Let's make HAARP great again!</​h1>"​
 +html+="<​div id='​map'​ class='​smallmap'></​div>"​
 +html+="<​br><​p>​Welcome! You can download the <a href='​./​brmmeteo.json'​ target='​_blank'>​source data as JSON file</​a><​br>"​
 +html+="​This site is owned and governed by members of the <a href='​https://​brmlab.cz'​ target='​_blank'>​hackerspace brmlab</​a>​. See our wiki page for <a href='​https://​brmlab.cz/​project/​brmmeteo/​start'​ target='​_blank'>​details and contact info</​a><​br>​License:​ CC-BY-SA</​p>"​
 +html+="</​body>"​
 +html+="​$js"​
 +html+='<​script src="​./​brmmeteo.js"></​script>'​
 +html+="</​html>"​
 +
 +echo "​$html"​ > "​$2"​
 </​code>​ </​code>​
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki