Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # **************************************************************************
- # Creator: Remo Tomasi
- #
- # NOTE: we need to install jq and to use conv2htm.sh and phantomjs
- # **************************************************************************
- # set the environment: these files as useful to save and use temporary datas
- if [ -e wjson.json ]; then rm wjson.json; fi
- if [ -e dati.csv ]; then rm dati.csv; fi
- if [ -e finalDatas.csv ]; then rm finalDatas.csv; fi
- if [ -e tmp.csv ]; then rm tmp.csv; fi
- touch wjson.json dati.csv finalDatas.csv
- # creation of the first line (columns)
- echo -e " Date\tTime\tTemp\tDewP\tHum\tCloud\tRain\tWindS\tWindDir\tSky\tPress\tLow\tMed\tHigh\tChanceRain\tChanceSnow\tZeroLevel" > finalDatas.csv
- # download of json datas and save the wjson file
- wget "http://ws1.metcheck.com/ENGINE/v9_0/json.asp?lat=40.4&lon=18.2&lid=22553" 2>/dev/null -O - > wjson.json
- # loop to obtain infos from the json file: here we use jq
- i=0
- while [ $i -lt `jq '.metcheckData.forecastLocation.forecast | length' wjson.json` ]; do
- 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
- echo -e "\t" >> dati.csv
- let i+=1
- done
- # finishing the informations formatting datas in various formats
- cat dati.csv | tr '\n' ',' | tr '\t' '\n' | tr ',' '\t' | sed 's/:00:00.00//g' | tr ' ' '-' | tr 'T' '\t' | tr '\t' ' ' >> finalDatas.csv
- sed -i '2d' finalDatas.csv # first two lines
- cat finalDatas.csv | cut -d' ' -f2- > tmp.csv # temporary file to eliminate first cloumn
- cat tmp.csv > finalDatas.csv # transfer in a new file
- head -74 finalDatas.csv > weatherForecast.csv # only 3 days of forecasting
- 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
- sed -i 's/n 0 W/n WindS W/g' tmp.csv # column from 0 to WindS
- cat tmp.csv > weatherForecast.csv
- ./conv2htm.sh weatherForecast.csv > weatherForecast.html # csv to html conversion
- phantomjs rasterize.js weatherForecast.html weatherForecastData.png # html to png conversion
- ./graph.pg > weatherForecastGraph.png # creating graph by gnuplot
- ./cloud.pg > weatherForecastCloud.png
- ./pressure.pg > weatherForecastPressure.png
- ./zeroLevel.pg > weatherForecastZeroLevel.png
- # final image composition of the 3 previous graphs
- # convert weatherForecastGraph.png weatherForecastCloud.png weatherForecastPressure.png +append weatherForecastFinal.png
- convert \( weatherForecastGraph.png weatherForecastPressure.png -append \) \( weatherForecastCloud.png weatherForecastZeroLevel.png -append \) +append weatherForecastFinal.png
- rm tmp.csv # remove temporary or useless files
Advertisement
Add Comment
Please, Sign In to add comment