bom 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/bin/sh
  2. usage="
  3. Download weather information from the AU BoM
  4. Usage: $0 [options]
  5. Options:
  6. -u, --update Update data sources (preceeds other options)
  7. -r, --rain_y Yesterday's rainfall
  8. --rain_fig_y Yesterday's rainfall figures
  9. --rain_t Today's rainfall
  10. --rain_fig_t Today's rainfall figures
  11. --rain_n Rainfall over last hour
  12. --rain_ani Animation of last 6 hours rainfall
  13. -l, --radar Radar loop
  14. -f, --forecast Local forecast
  15. --fire State fire danger ratings
  16. --forest_fire Forest fire danger heatmap
  17. --grass_fire Grass fire danger heatmap
  18. --national National weather
  19. See ftp://ftp2.bom.gov.au/anon/gen/README for more information."
  20. # BoM ftp details
  21. host='ftp2.bom.gov.au' # Remote host
  22. rdir='/anon/gen/' # Remote ftp base directory
  23. ldir="$HOME/.bom_data/" # Directory to keep downloaded data
  24. # Programs
  25. pager='/usr/bin/less' # Text pager
  26. viewer='/usr/local/bin/display' # Image viewer
  27. local_forecast='fwo/IDV10716.txt' # Mt Dandenong Forecast
  28. national_weather='fwo/IDV17300.txt' # National weather forecast
  29. radar_id='IDR022' # BoM radar image set
  30. radar_mask="radar/${radar_id}.T.*.png" # Images to include in the loop
  31. radar_bg="${radar_id}.background.png" # Image generated by layering the following list
  32. radar_bg_list="radar_transparencies/${radar_id}.background.png
  33. radar_transparencies/${radar_id}.topography.png
  34. radar_transparencies/${radar_id}.waterways.png
  35. radar_transparencies/${radar_id}.locations.png"
  36. # Rainfall images
  37. rain_old='fwo/IDV65316.gif' # Rainfall Yesterday (till 9am)
  38. rain_new='fwo/IDV65317.gif' # Rainfall Today (since 9am)
  39. rain_1hr='fwo/IDV65318.gif' # Rainfall Now (last hour)
  40. rain_old_fig='fwo/IDV65323.gif' # Rainfall Yesterday (location figures till 9am)
  41. rain_new_fig='fwo/IDV65324.gif' # Rainfall Today (since 9am)
  42. rain_1hr_fig='fwo/IDV65325.gif' # Rainfall Now (last hour)
  43. rain_2hr_fig='fwo/IDV65326.gif' # 1hr earlier
  44. rain_3hr_fig='fwo/IDV65327.gif' # 2hrs earlier
  45. rain_4hr_fig='fwo/IDV65328.gif' # 3hrs earlier
  46. rain_5hr_fig='fwo/IDV65329.gif' # 4hrs earlier
  47. rain_6hr_fig='fwo/IDV65330.gif' # 5hrs earlier
  48. state_fire='fwo/IDV18555.txt' # Victorian fire danger ratings
  49. state_forest_fire='fwo/IDV65406.png' # Victorian forest fire danger heatmap
  50. state_grass_fire='fwo/IDV65426.png' # Victorian grass fire danger heatmap
  51. get() {
  52. [ ! -d "$ldir" ] && mkdir "$ldir"
  53. [ ! -d "$ldir$(dirname "$1")" ] && mkdir "$ldir$(dirname "$1")"
  54. if [ -n "$update" ]
  55. then
  56. rfile="$rdir$1"
  57. lfile="$ldir$1"
  58. if [ -f "$lfile" ]
  59. then
  60. ftp -ain "$host" <<- .
  61. quote USER anonymous
  62. quote PASS no@email.com
  63. newer "$rfile" "$lfile"
  64. .
  65. else
  66. ftp -ain "$host" <<- .
  67. quote USER anonymous
  68. quote PASS no@email.com
  69. get "$rfile" "$lfile"
  70. .
  71. fi
  72. fi
  73. }
  74. viewer() {
  75. for file in $*
  76. do
  77. if [ ! -f "$file" ]
  78. then echo "$file not found"
  79. else $viewer "$*"
  80. fi
  81. done
  82. }
  83. pager() {
  84. for file in $*
  85. do
  86. if [ ! -f "$file" ]
  87. then echo "$file not found"
  88. else $pager "$*"
  89. fi
  90. done
  91. }
  92. mkradar() {
  93. # Make the background map
  94. if [ ! -f "$ldir$radar_bg" ]
  95. then
  96. for image in $radar_bg_list
  97. do
  98. get "$image"
  99. if [ -z "$bg" ]
  100. then
  101. bg="$image"; continue
  102. else
  103. composite "$ldir$image" "$ldir$bg" "$ldir$bg"
  104. fi
  105. done
  106. mv "$ldir$bg" "$ldir$radar_bg" && rm -rf "$(dirname "$ldir$bg")"
  107. fi
  108. # Get the images
  109. #TODO: Somehow use the get() function instead of wget
  110. [ -d "$ldir$(dirname "$radar_mask")" ] && rm -r "$ldir$(dirname "$radar_mask")"
  111. wget -nv -P "$ldir$(dirname "$radar_mask")" "ftp://${host}$rdir$radar_mask"
  112. # Make the animation frames
  113. image_list="$(find "$ldir" -iname "$(basename "$radar_mask")")"
  114. if [ -n "$image_list" ]
  115. then
  116. for image in $image_list
  117. do
  118. composite "$image" "$ldir$radar_bg" "$image"
  119. done
  120. fi
  121. }
  122. #[ -z "$1" ] && pager "$ldir$local_forecast"
  123. [ -z "$1" ] && echo "$usage"
  124. while [ "$#" -ne '0' ]
  125. do
  126. arg="$1"
  127. shift
  128. case "$arg" in
  129. '-u'|'--update') update=1 ;;
  130. '-f'|'--forecast')
  131. get "$local_forecast"
  132. pager "$ldir$local_forecast"
  133. ;;
  134. '--national')
  135. get "$national_weather"
  136. pager "$ldir$national_weather"
  137. ;;
  138. '-r'|'--rain_y')
  139. get "$rain_old"
  140. viewer "$ldir$rain_old"
  141. ;;
  142. '--rain_t')
  143. get "$rain_new"
  144. viewer "$ldir$rain_new"
  145. ;;
  146. '--rain_n')
  147. get "$rain_1hr"
  148. viewer "$ldir$rain_1hr"
  149. ;;
  150. '--rain_fig_y')
  151. get "$rain_old_fig"
  152. viewer "$ldir$rain_old_fig"
  153. ;;
  154. '--rain_fig_t')
  155. get "$rain_new_fig"
  156. viewer "$ldir$rain_new_fig"
  157. ;;
  158. '--rain_ani')
  159. get "$rain_1hr_fig"
  160. get "$rain_2hr_fig"
  161. get "$rain_3hr_fig"
  162. get "$rain_4hr_fig"
  163. get "$rain_5hr_fig"
  164. get "$rain_6hr_fig"
  165. animate -delay 100 "$ldir$rain_1hr_fig" "$ldir$rain_2hr_fig" "$ldir$rain_3hr_fig" "$ldir$rain_4hr_fig" "$ldir$rain_5hr_fig" "$ldir$rain_6hr_fig"
  166. ;;
  167. '-l'|'--radar')
  168. # Download and build animation
  169. [ -n "$update" ] && mkradar
  170. # Play the animation
  171. [ -d "$ldir$(dirname "$radar_mask")" ] && animate -delay 100 "$ldir$radar_mask"
  172. ;;
  173. '--fire')
  174. get "$state_fire"
  175. pager "$ldir$state_fire"
  176. ;;
  177. '--forest_fire')
  178. get "$state_forest_fire"
  179. viewer "$ldir$state_forest_fire"
  180. ;;
  181. '--grass_fire')
  182. get "$state_grass_fire"
  183. viewer "$ldir$state_grass_fire"
  184. ;;
  185. *)
  186. echo "$usage"
  187. exit
  188. ;;
  189. esac
  190. done