remotomasi

mex.sh - WeatherForecast Lecce (Remo Tomasi + Metcheck.com)

Oct 13th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.73 KB | None | 0 0
  1. #!/bin/bash
  2. # **************************************************************************
  3. # Creator: Remo Tomasi
  4. #
  5. # NOTE: we need to install jq and to use conv2htm.sh and phantomjs
  6. # **************************************************************************
  7. # set the environment: these files as useful to save and use temporary datas
  8. if [ -e wjson.json ]; then rm wjson.json; fi
  9. if [ -e dati.csv ]; then rm dati.csv; fi
  10. if [ -e finalDatas.csv ]; then rm finalDatas.csv; fi
  11. if [ -e tmp.csv ]; then rm tmp.csv; fi
  12. touch wjson.json dati.csv finalDatas.csv
  13.  
  14. # creation of the first line (columns)
  15. echo -e " Date\tTime\tTemp\tDewP\tHum\tCloud\tRain\tWindS\tWindDir\tSky\tPress\tLow\tMed\tHigh\tChanceRain\tChanceSnow\tZeroLevel" > finalDatas.csv
  16.  
  17. # download of json datas and save the wjson file
  18. wget "http://ws1.metcheck.com/ENGINE/v9_0/json.asp?lat=40.4&lon=18.2&lid=22553" 2>/dev/null -O - > wjson.json
  19.  
  20. # loop to obtain infos from the json file: here we use jq
  21. i=0
  22. while [ $i -lt  `jq '.metcheckData.forecastLocation.forecast | length' wjson.json` ]; do
  23.   cat wjson.json | jq --raw-output .metcheckData.forecastLocation.forecast["$i"].utcTime,.metcheckData.forecastLocation.forecast["$i"].temperature,.metcheckData.forecastLocation.forecast["$i"].dewpoint,.metcheckData.forecastLocation.forecast["$i"].humidity,.metcheckData.forecastLocation.forecast["$i"].totalcloud,.metcheckData.forecastLocation.forecast["$i"].rain,.metcheckData.forecastLocation.forecast["$i"].windspeed,.metcheckData.forecastLocation.forecast["$i"].windletter,.metcheckData.forecastLocation.forecast["$i"].iconName,.metcheckData.forecastLocation.forecast["$i"].meansealevelpressure,.metcheckData.forecastLocation.forecast["$i"].lowcloud,.metcheckData.forecastLocation.forecast["$i"].medcloud,.metcheckData.forecastLocation.forecast["$i"].highcloud,.metcheckData.forecastLocation.forecast["$i"].chanceofrain,.metcheckData.forecastLocation.forecast["$i"].chanceofrain,.metcheckData.forecastLocation.forecast["$i"].freezinglevel >> dati.csv
  24.   echo -e "\t" >> dati.csv
  25.   let i+=1
  26. done
  27.  
  28. # finishing the informations formatting datas in various formats
  29. cat dati.csv | tr '\n' ',' | tr '\t' '\n' | tr ',' '\t' | sed 's/:00:00.00//g' | tr ' ' '-' | tr 'T' '\t' | tr '\t' ' ' >> finalDatas.csv
  30. sed -i '2d' finalDatas.csv                                              # first two lines
  31. cat finalDatas.csv | cut -d' ' -f2- > tmp.csv                           # temporary file to eliminate first cloumn
  32. cat tmp.csv > finalDatas.csv                                            # transfer in a new file
  33. head -74 finalDatas.csv > weatherForecast.csv                           # only 3 days of forecasting
  34. awk 'BEGIN{FS=OFS=" "}{print $1,$2,$3,$4,$5,$6,$7,$8*1.619,$9,$10,$11,$12,$13,$14,$15,$16,$17 }' weatherForecast.csv > tmp.csv  # convert wind power from miles/h to km/h
  35. sed -i 's/n 0 W/n WindS W/g' tmp.csv                                    # column from 0 to WindS
  36. cat tmp.csv > weatherForecast.csv
  37. ./conv2htm.sh weatherForecast.csv > weatherForecast.html                # csv to html conversion
  38. phantomjs rasterize.js weatherForecast.html weatherForecastData.png     # html to png conversion
  39. ./graph.pg > weatherForecastGraph.png                                   # creating graph by gnuplot
  40. ./cloud.pg > weatherForecastCloud.png
  41. ./pressure.pg > weatherForecastPressure.png
  42. ./zeroLevel.pg > weatherForecastZeroLevel.png
  43. # final image composition of the 3 previous graphs
  44. # convert weatherForecastGraph.png weatherForecastCloud.png weatherForecastPressure.png +append weatherForecastFinal.png
  45. convert \( weatherForecastGraph.png weatherForecastPressure.png -append \) \( weatherForecastCloud.png weatherForecastZeroLevel.png -append \) +append weatherForecastFinal.png
  46. rm tmp.csv  # remove temporary or useless files
Advertisement
Add Comment
Please, Sign In to add comment