Advertisement
Guest User

Untitled

a guest
Feb 16th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #function: test_image_day
  4. test_image_day () {
  5. case $1 in
  6. su)
  7. echo 1su
  8. ;;
  9. msu)
  10. echo 2msu
  11. ;;
  12. psu)
  13. echo 3psu
  14. ;;
  15. ic)
  16. echo 4ic
  17. ;;
  18. h)
  19. echo 5h
  20. ;;
  21. mc)
  22. echo 6mc
  23. ;;
  24. c)
  25. echo 7c
  26. ;;
  27. d)
  28. echo 8d
  29. ;;
  30. f)
  31. echo 9f
  32. ;;
  33. s)
  34. echo 10s
  35. ;;
  36. mcs)
  37. echo 11mcs
  38. ;;
  39. psus)
  40. echo 12psus
  41. ;;
  42. t)
  43. echo 13t
  44. ;;
  45. mct)
  46. echo 14mct
  47. ;;
  48. psut)
  49. echo 15psut
  50. ;;
  51. r)
  52. echo 16r
  53. ;;
  54. fl)
  55. echo 17fl
  56. ;;
  57. mcfl)
  58. echo 18mcfl
  59. ;;
  60. psfl)
  61. echo 19psfl
  62. ;;
  63. sn)
  64. echo 20sn
  65. ;;
  66. mcsn)
  67. echo 21mcsn
  68. ;;
  69. i)
  70. echo 22i
  71. ;;
  72. sl)
  73. echo 23sl
  74. ;;
  75. fr)
  76. echo 24fr
  77. ;;
  78. rsn)
  79. echo 25rsn
  80. ;;
  81. w)
  82. echo 26w
  83. ;;
  84. ho)
  85. echo 27ho
  86. ;;
  87. co)
  88. echo 28co
  89. ;;
  90. cl)
  91. echo 29cl
  92. ;;
  93. mcl)
  94. echo 31mcl
  95. ;;
  96. pc)
  97. echo 32pc
  98. ;;
  99. pcs)
  100. echo 36pcs
  101. ;;
  102. pct)
  103. echo 38pct
  104. ;;
  105. esac
  106. }
  107.  
  108. #function: test_image_night
  109. test_image_night () {
  110. case $1 in
  111. su)
  112. echo 1su
  113. ;;
  114. msu)
  115. echo 2msu
  116. ;;
  117. psu)
  118. echo 3psu
  119. ;;
  120. c)
  121. echo 7c
  122. ;;
  123. d)
  124. echo 8d
  125. ;;
  126. f)
  127. echo 9f
  128. ;;
  129. s)
  130. echo 10s
  131. ;;
  132. psus)
  133. echo 12psus
  134. ;;
  135. t)
  136. echo 13t
  137. ;;
  138. psut)
  139. echo 15psut
  140. ;;
  141. r)
  142. echo 16r
  143. ;;
  144. fl)
  145. echo 17fl
  146. ;;
  147. psfl)
  148. echo 19psfl
  149. ;;
  150. sn)
  151. echo 20sn
  152. ;;
  153. i)
  154. echo 22i
  155. ;;
  156. sl)
  157. echo 23sl
  158. ;;
  159. fr)
  160. echo 24fr
  161. ;;
  162. rsn)
  163. echo 25rsn
  164. ;;
  165. ho)
  166. echo 27ho
  167. ;;
  168. co)
  169. echo 28co
  170. ;;
  171. cl)
  172. echo 29cl
  173. ;;
  174. w)
  175. echo 30w
  176. ;;
  177. mcl)
  178. echo 31mcl
  179. ;;
  180. pc)
  181. echo 32pc
  182. ;;
  183. ic)
  184. echo 33ic
  185. ;;
  186. h)
  187. echo 34h
  188. ;;
  189. mc)
  190. echo 35mc
  191. ;;
  192. pcs)
  193. echo 36pcs
  194. ;;
  195. mcs)
  196. echo 37mcs
  197. ;;
  198. pct)
  199. echo 38pct
  200. ;;
  201. mct)
  202. echo 39mct
  203. ;;
  204. mcfl)
  205. echo 40mcfl
  206. ;;
  207. mcsn)
  208. echo 41mcsn
  209. ;;
  210. esac
  211. }
  212.  
  213.  
  214. #put your Accuweather address here
  215. address="http://www.accuweather.com/ru/ua/kiev/324505/weather-forecast/324505"
  216.  
  217. loc_id=$(echo $address|sed 's/\/weather-forecast.*$//'|sed 's/^.*\///')
  218. last_number=$(echo $address|sed 's/^.*\///')
  219.  
  220. curr_addr="$(echo $address|sed 's/weather-forecast.*$//')"current-weather/"$last_number"
  221.  
  222. addr1="$(echo $address|sed 's/weather-forecast.*$//')"daily-weather-forecast/"$last_number"
  223. addr2="$addr1"?day=6
  224.  
  225. kill -STOP $(pidof conky)
  226. killall wget
  227.  
  228. wget --save-cookies $HOME/Accuweather_Conky_Int_Images/cookie -O $HOME/Accuweather_Conky_Int_Images/curr_cond_raw $curr_addr
  229. wget --load-cookies $HOME/Accuweather_Conky_Int_Images/cookie -O $HOME/Accuweather_Conky_Int_Images/first_days_raw $addr1
  230. wget --load-cookies $HOME/Accuweather_Conky_Int_Images/cookie -O $HOME/Accuweather_Conky_Int_Images/last_days_raw $addr2
  231.  
  232. #Current Conditions - curr_cond file
  233. if [[ -s $HOME/Accuweather_Conky_Int_Images/curr_cond_raw ]]; then
  234.  
  235. egrep -i '"detail-tab-panel |>Today<\/a>|>Tonight<\/a>|>Early AM<\/a>|>Overnight<\/a>|>Mon<\/a>|>Tue<\/a>|>Wed<\/a>|>Thu<\/a>|>Fri<\/a>|>Sat<\/a>|>Sun<\/a>|icon i-|"cond"|"temp"|var d = '\''|var s = '\''|Humidity: |Pressure: |Cloud Cover: |UV Index: |Dew Point: |Precipitation(1 hr): |Visibility: |"start">|"finish">' $HOME/Accuweather_Conky_Int_Images/curr_cond_raw > $HOME/Accuweather_Conky_Int_Images/curr_cond
  236. sed -i -e 's/^[ \t]*//g' -e 's/^.*icon i-//g' -e 's/^.*"cond">//g' -e 's/>Lo</\n/g' -e 's/RealFeel/\n/g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  237. sed -i -e 's/^.*"#">//g' -e 's/^.*<strong class="temp"//g' -e 's/^>//g' -e 's/<span>&deg.*$//g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  238. sed -i -e 's/<\/a>.*$//g' -e 's/\/span> //g' -e 's/var d = //g' -e 's/var s = //g' -e 's/"temp">/\n/g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  239. sed -i -e 's/^.*"start">//g' -e 's/^.*"finish">//g' -e 's/<li>//g' -e 's/<strong>//g' -e 's/<<span.*$//g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  240. sed -i -e 's/<\/span>//g' -e 's/<\/strong><\/li>//g' -e 's/ "><\/div>//g' -e 's/'\''//g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  241. sed -i -e 's/"><\/div>//g' -e 's/^.*; //g' -e 's/&#.*$//g' -e 's/ i-alarm.*$//g' -e 's/;//g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  242. sed -i -e 's/Humidity: //g' -e 's/Pressure: //g' -e 's/Cloud Cover: //g' -e 's/UV Index: //g' -e 's/Dew Point: //g' -e 's/Visibility: //g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  243. sed -i -e 's/^.*detail-tab-panel //g' -e 's/">//g' -e 's/\r//g' -e 's/ *$//g' -e 's/mb.*$/mb/g' $HOME/Accuweather_Conky_Int_Images/curr_cond
  244. sed -i '1,12d' $HOME/Accuweather_Conky_Int_Images/curr_cond
  245. time=$(sed -n 1p $HOME/Accuweather_Conky_Int_Images/curr_cond)
  246. if [[ $time == Tonight || $time == Overnight || $time == "Early AM" ]]; then
  247. sed -i 3a- $HOME/Accuweather_Conky_Int_Images/curr_cond
  248. fi
  249. line35=$(sed -n 35p $HOME/Accuweather_Conky_Int_Images/curr_cond)
  250. sed -i '35d' $HOME/Accuweather_Conky_Int_Images/curr_cond
  251. sed -i 35a$line35 $HOME/Accuweather_Conky_Int_Images/curr_cond
  252. time=$(sed -n 26p $HOME/Accuweather_Conky_Int_Images/curr_cond)
  253. image=$(sed -n 27p $HOME/Accuweather_Conky_Int_Images/curr_cond)
  254. if [[ $time == day ]]; then
  255. sed -i 27s/$image/$(test_image_day $image)/ $HOME/Accuweather_Conky_Int_Images/curr_cond
  256. elif [[ $time == night ]]; then
  257. sed -i 27s/$image/$(test_image_night $image)/ $HOME/Accuweather_Conky_Int_Images/curr_cond
  258. fi
  259. cp $HOME/Accuweather_Conky_Int_Images/Forecast_Images/$(sed -n 27p $HOME/Accuweather_Conky_Int_Images/curr_cond).png $HOME/Accuweather_Conky_Int_Images/cc.png
  260. fi
  261.  
  262.  
  263. #First 5days - first_days file
  264. if [[ -s $HOME/Accuweather_Conky_Int_Images/first_days_raw ]]; then
  265.  
  266. sed -i '/<div class="column-1 clearfix">/,/<div id=\"feature-history\">/!d' $HOME/Accuweather_Conky_Int_Images/first_days_raw
  267. egrep -i '>Today<|<p>[a-z]|>Mon<\/a>|>Tue<\/a>|>Wed<\/a>|>Thu<\/a>|>Fri<\/a>|>Sat<\/a>|>Sun<\/a>|icon i-|"cond"|"temp"|realfeel">RealFeel|realfeel">Precipitation' $HOME/Accuweather_Conky_Int_Images/first_days_raw > $HOME/Accuweather_Conky_Int_Images/first_days
  268.  
  269. sed -i -e 's/^[ \t]*//g' -e 's/^.*icon i-//g' -e 's/^.*"cond">//g' -e 's/>Lo</\n/g' $HOME/Accuweather_Conky_Int_Images/first_days
  270. sed -i -e 's/ "><\/div>//g' -e 's/"><\/div>//g' -e 's/^.*"temp">//g' -e 's/<span>&deg.*$//g' $HOME/Accuweather_Conky_Int_Images/first_days
  271. sed -i -e 's/<p>//g' -e 's/<\/p>//g' -e 's/^.*"#">//g' -e 's/\/span> //g' -e 's/^.*>Precipitation //g' -e 's/^.*; //g' $HOME/Accuweather_Conky_Int_Images/first_days
  272. sed -i -e 's/&#.*$//g' -e 's/<.*$//g' -e 's/ i-alarm.*$//g' -e 's/\r//g' -e 's/ *$//g' $HOME/Accuweather_Conky_Int_Images/first_days
  273. sed -i -e 's/Today/TODAY/' -e 's/Mon$/MONDAY/' -e 's/Tue$/TUESDAY/' -e 's/Wed$/WEDNESDAY/' -e 's/Thu$/THURSDAY/' -e 's/Fri$/FRIDAY/' -e 's/Sat$/SATURDAY/' -e 's/Sun$/SUNDAY/' $HOME/Accuweather_Conky_Int_Images/first_days
  274. time=$(sed -n 1p $HOME/Accuweather_Conky_Int_Images/curr_cond)
  275. if [[ $time == Tonight || $time == Overnight || $time == "Early AM" ]]; then
  276. sed -i 2a- $HOME/Accuweather_Conky_Int_Images/first_days
  277. fi
  278. L1=$(sed -n 1p $HOME/Accuweather_Conky_Int_Images/first_days)
  279. if [[ $L1 == TODAY ]]; then
  280. sed -i 1d $HOME/Accuweather_Conky_Int_Images/first_days
  281. fi
  282. for (( i=6; i<=21; i+=5 ))
  283. do
  284. image_raw=$(sed -n "${i}"p $HOME/Accuweather_Conky_Int_Images/first_days)
  285. sed -i ${i}s/$image_raw/$(test_image_day $image_raw)/ $HOME/Accuweather_Conky_Int_Images/first_days
  286. cp $HOME/Accuweather_Conky_Int_Images/Forecast_Images/$(sed -n ${i}p $HOME/Accuweather_Conky_Int_Images/first_days).png $HOME/Accuweather_Conky_Int_Images/$i.png
  287. done
  288. image_raw=$(sed -n 25p $HOME/Accuweather_Conky_Int_Images/first_days)
  289. sed -i 25s/$image_raw/$(test_image_day $image_raw)/ $HOME/Accuweather_Conky_Int_Images/first_days
  290. cp $HOME/Accuweather_Conky_Int_Images/Forecast_Images/$(sed -n 25p $HOME/Accuweather_Conky_Int_Images/first_days).png $HOME/Accuweather_Conky_Int_Images/tod.png
  291. image_raw=$(sed -n 30p $HOME/Accuweather_Conky_Int_Images/first_days)
  292. sed -i 30s/$image_raw/$(test_image_day $image_raw)/ $HOME/Accuweather_Conky_Int_Images/first_days
  293. cp $HOME/Accuweather_Conky_Int_Images/Forecast_Images/$(sed -n 30p $HOME/Accuweather_Conky_Int_Images/first_days).png $HOME/Accuweather_Conky_Int_Images/ton.png
  294.  
  295. fi
  296.  
  297.  
  298. #Last 5days - last_days file
  299. if [[ -s $HOME/Accuweather_Conky_Int_Images/last_days_raw ]]; then
  300.  
  301. sed -i '/<div class="column-1 clearfix">/,/<div id=\"feature-history\">/!d' $HOME/Accuweather_Conky_Int_Images/last_days_raw
  302. egrep -i '>Mon<\/a>|>Tue<\/a>|>Wed<\/a>|>Thu<\/a>|>Fri<\/a>|>Sat<\/a>|>Sun<\/a>|icon i-|"cond"|"temp"|realfeel">RealFeel|realfeel">Precipitation' $HOME/Accuweather_Conky_Int_Images/last_days_raw > $HOME/Accuweather_Conky_Int_Images/last_days
  303. sed -i -e 's/^[ \t]*//g' -e 's/^.*icon i-//g' -e 's/^.*"cond">//g' -e 's/>Lo</\n/g' $HOME/Accuweather_Conky_Int_Images/last_days
  304. sed -i -e 's/ "><\/div>//g' -e 's/"><\/div>//g' -e 's/^.*"temp">//g' -e 's/<span>&deg.*$//g' $HOME/Accuweather_Conky_Int_Images/last_days
  305. sed -i -e 's/^.*"#">//g' -e 's/\/span> //g' -e 's/^.*>Precipitation //g' -e 's/^.*; //g' $HOME/Accuweather_Conky_Int_Images/last_days
  306. sed -i -e 's/&#.*$//g' -e 's/<.*$//g' -e 's/ i-alarm.*$//g' -e 's/\r//g' -e 's/ *$//g' $HOME/Accuweather_Conky_Int_Images/last_days
  307. sed -i -e 's/Mon$/MONDAY/' -e 's/Tue$/TUESDAY/' -e 's/Wed$/WEDNESDAY/' -e 's/Thu$/THURSDAY/' -e 's/Fri$/FRIDAY/' -e 's/Sat$/SATURDAY/' -e 's/Sun$/SUNDAY/' $HOME/Accuweather_Conky_Int_Images/last_days
  308. for (( i=2; i<=22; i+=5 ))
  309. do
  310. image_raw=$(sed -n "${i}"p $HOME/Accuweather_Conky_Int_Images/last_days)
  311. sed -i ${i}s/$image_raw/$(test_image_day $image_raw)/ $HOME/Accuweather_Conky_Int_Images/last_days
  312. cp $HOME/Accuweather_Conky_Int_Images/Forecast_Images/$(sed -n ${i}p $HOME/Accuweather_Conky_Int_Images/last_days).png $HOME/Accuweather_Conky_Int_Images/last_$i.png
  313. done
  314.  
  315. fi
  316.  
  317. #messages file
  318. sed -n 28p $HOME/Accuweather_Conky_Int_Images/curr_cond | cut -c -20 > $HOME/Accuweather_Conky_Int_Images/messages
  319. sed -n 29p $HOME/Accuweather_Conky_Int_Images/first_days | cut -c -20 >> $HOME/Accuweather_Conky_Int_Images/messages
  320. sed -n 34p $HOME/Accuweather_Conky_Int_Images/first_days | cut -c -20 >> $HOME/Accuweather_Conky_Int_Images/messages
  321. for (( i=7; i<=22; i+=5 ))
  322. do
  323. sed -n ${i}p $HOME/Accuweather_Conky_Int_Images/first_days | cut -c -20 >> $HOME/Accuweather_Conky_Int_Images/messages
  324. done
  325. for (( i=3; i<=23; i+=5 ))
  326. do
  327. sed -n ${i}p $HOME/Accuweather_Conky_Int_Images/last_days | cut -c -20 >> $HOME/Accuweather_Conky_Int_Images/messages
  328. done
  329.  
  330. kill -CONT $(pidof conky)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement