oxhak

OpenWeatherMap with Shell Script

Dec 15th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. YOUR_API_KEY=CHANGEME
  4. YOUR_CITY_ID=CHANGEME
  5.  
  6. temps=`date +%s`;
  7. data=`wget  -q -O - "http://api.openweathermap.org/data/2.5/weather?id=${YOUR_CITY_ID}&appid=${YOUR_API_KEY}&lang=fr&units=metric&lol=$temps" --delete-after`
  8. temperature=`echo ${data} | sed -n 's#.*{"temp":\(.*\),"pressure".*#\1#p'`
  9. temperaturetext=`echo ${data} | sed -n 's#.*"description":"\(.*\)","icon":.*#\1#p'`
  10. if [[ ${temperature} =~ "." ]]; then
  11.   temperature=`expr $(echo "$temperature" |cut -f1 -d\.) + 1`;
  12. fi
  13. echo "$temperature" > /dev/shm/weathertemp.txt;
  14. echo "$temperaturetext" > /dev/shm/weathertemptext.txt;
  15.  
  16. #weather files are now in /dev/shm/ for your conky. ;)
  17. #thanks @nazgullien !
Advertisement
Add Comment
Please, Sign In to add comment