Advertisement
Guest User

Pimatic Holiday phinfo.sh

a guest
Nov 18th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # phinfo.sh [yyyymmdd]
  4. #
  5. # post current date to pimatic, if true enhanced by name of public holiday
  6. # "yyyymmdd" # run script in test mode
  7. #-----------------------------------------------------------------------------
  8. . /home/pi/pimatic-holiday/pimaticAPI.sh
  9.  
  10. PIMATIC_VAR1="publicHoliday"
  11. PIMATIC_VAR2="today"
  12. PIMATIC_VAR3="sunposition"
  13. #
  14. # check and get runstring parameter
  15. #
  16. if [ "$1" ]
  17. then
  18. qday=$1
  19. DEBUG="true"
  20. else
  21. qday="today"
  22. fi
  23. qdate=$(date -d "$qday" +"%d.%m.%Y")
  24.  
  25. public_holiday=$(curl -s http://www.ferienkalender.com/ferien_deutschland/Hessen/2015-ferien-hessen.htm | grep "$qdate" | awk 'BEGIN{RS="</td></tr><tr";FS="><td align=left>";} {print $2,$3;}'| grep "$qdate" | awk 'BEGIN{FS="<b>";} {print $3,$2;}' | awk 'BEGIN{FS="</b></td><td align=right>";} {print $2," - ",$1;}' )
  26.  
  27. if [ "$public_holiday" ]
  28. then
  29. phday="true"
  30. else
  31. phday="false"
  32. public_holiday="$(date -d "$qday" +"%A"), $qdate"
  33. fi
  34.  
  35. if [ "$DEBUG" = "true" ]; then echo ":$phday:$public_holiday:"; fi
  36.  
  37. pimatic_var_value="\"$phday\""
  38. write_to_pimatic $PIMATIC_VAR1 "$pimatic_var_value"
  39.  
  40. pimatic_var_value="\"$public_holiday\""
  41. write_to_pimatic $PIMATIC_VAR2 "$pimatic_var_value"
  42. #
  43. # get sunrise and sunset time
  44. #
  45. sunrise=$(curl -s http://weather.yahooapis.com/forecastrss?w=642800 | grep astronomy | awk -F\" '{print $2}' | { date -f - +%R; })
  46. sunset=$(curl -s http://weather.yahooapis.com/forecastrss?w=644719 | grep astronomy | awk -F\" '{print $4}'|{ date -f - +%R; })
  47.  
  48. sunposition="Aufgang $sunrise Uhr, Untergang $sunset Uhr"
  49.  
  50. if [ "$DEBUG" = "true" ]; then echo "$sunposition"; fi
  51.  
  52. pimatic_var_value="\"$sunposition\""
  53. write_to_pimatic $PIMATIC_VAR3 "$pimatic_var_value"
  54.  
  55. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement