Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ImagesDir="/srv/informers/img"
- Data=`curl -s "http://weather.yahooapis.com/forecastrss?p=RSXX1629&u=c" 2>/dev/null`
- function ConditionToString {
- case "$1" in
- 0)
- echo "Торнадо"
- ;;
- 1)
- echo "Тропический шторм"
- ;;
- 2)
- echo "Ураган"
- ;;
- 3)
- echo "Серьезная гроза"
- ;;
- 4)
- echo "Гроза"
- ;;
- 5)
- echo "Дождь со снегом"
- ;;
- 6)
- echo "Дождь со льдом"
- ;;
- 7)
- echo "Снего со льдом"
- ;;
- 8)
- echo "Морозная изморось"
- ;;
- 9)
- echo "Изморось"
- ;;
- 10)
- echo "Ледяной дождь"
- ;;
- 11)
- echo "Дождь"
- ;;
- 12)
- echo "Дождь"
- ;;
- 13)
- echo "Хлопья снега"
- ;;
- 14)
- echo "Легкий снег"
- ;;
- 15)
- echo "Пурга"
- ;;
- 16)
- echo "Снег"
- ;;
- 17)
- echo "Град"
- ;;
- 18)
- echo "Дождь со снегом"
- ;;
- 19)
- echo "Пыльно"
- ;;
- 20)
- echo "Туман"
- ;;
- 21)
- echo "Дымка"
- ;;
- 22)
- echo "Дымно"
- ;;
- 23)
- echo "Неспокойно"
- ;;
- 24)
- echo "Ветрено"
- ;;
- 25)
- echo "Морозно"
- ;;
- 26)
- echo "Облачно"
- ;;
- 27)
- echo "Облачно"
- ;;
- 28)
- echo "Облачно"
- ;;
- 29)
- echo "Легкая облачность"
- ;;
- 30)
- echo "Легкая облачность"
- ;;
- 31)
- echo "Ясно"
- ;;
- 32)
- echo "Солнечно"
- ;;
- 33)
- echo "Ясно"
- ;;
- 34)
- echo "Ясно"
- ;;
- 35)
- echo "Дождь с градом"
- ;;
- 36)
- echo "Жара"
- ;;
- 37)
- echo "Редкие грозы"
- ;;
- 38)
- echo "Рассеяные грозы"
- ;;
- 39)
- echo "Рассеяные грозы"
- ;;
- 40)
- echo "Редкий дождь"
- ;;
- 41)
- echo "Сильный снег"
- ;;
- 42)
- echo "Плотный снег"
- ;;
- 43)
- echo "Сильный снег"
- ;;
- 44)
- echo "Местами облачно"
- ;;
- 45)
- echo "Ливень"
- ;;
- 46)
- echo "Вьюга"
- ;;
- 47)
- echo "Редкие грозы"
- ;;
- *)
- echo "Неизвестно"
- ;;
- esac
- }
- function DayToString {
- case "$1" in
- "Mon")
- echo "Понедельник"
- ;;
- "Tue")
- echo "Вторник"
- ;;
- "Wed")
- echo "Среда"
- ;;
- "Thu")
- echo "Четверг"
- ;;
- "Fri")
- echo "Пятница"
- ;;
- "Sat")
- echo "Суббота"
- ;;
- "Sun")
- echo "Воскресенье"
- ;;
- *)
- echo "Конец света"
- ;;
- esac
- }
- if [ ! -z "$Data" ]; then
- echo '<div class="mainlevel"><div id="weather">'
- CurTemp=`echo "$Data" | xmlstarlet sel -T -t -v "/rss/channel/item/yweather:condition/@temp"`
- if [ "$CurTemp" -gt 0 ]; then
- CurTemp="+$CurTemp"
- fi
- CurCondition=`echo "$Data" | xmlstarlet sel -T -t -v "/rss/channel/item/yweather:condition/@code"`
- CurConditionImage="$CurCondition.gif"
- if [ ! -f "$ImagesDir/$CurCondition.gif" ]; then
- curl -s -o "$ImagesDir/$CurCondition.gif" "http://l.yimg.com/a/i/us/we/52/$CurConditionImage"
- fi
- CurCondition=`ConditionToString "$CurCondition"`
- CurHumidity=`echo "$Data" | xmlstarlet sel -T -t -v "/rss/channel/yweather:atmosphere/@humidity"`
- CurWind=`echo "$Data" | xmlstarlet sel -T -t -v "/rss/channel/yweather:wind/@speed"`
- CurWind=`echo "$CurWind*1000/60/60" | bc`
- echo '<div id="today"><strong>Сейчас в Надыме</strong><br/>
- <h1><img style="vertical-align:middle;" src="data/weather.gif" alt="" />'"$CurTemp"'</h1>
- '"$CurCondition"'<br/>
- Ветер: '"$CurWind"'м/с<br/>
- Влажность: '"$CurHumidity"'%</div>'
- Forecast=`echo "$Data" | xmlstarlet sel -T -t -m "/rss/channel/item/yweather:forecast" -v "concat(@day,'|',@code,'|',@low,'|',@high,'|')"`
- Forecast1Day=`echo "$Forecast" | cut -f1 -d'|'`
- Forecast1Day=`DayToString "$Forecast1Day"`
- Forecast1Condition=`echo "$Forecast" | cut -f2 -d'|'`
- Forecast1ConditionImage="$Forecast1Condition.gif"
- if [ ! -f "$ImagesDir/$Forecast1Condition.gif" ]; then
- curl -s -o "$ImagesDir/$Forecast1Condition.gif" "http://l.yimg.com/a/i/us/we/52/$Forecast1ConditionImage"
- fi
- Forecast1Condition=`ConditionToString "$Forecast1Condition"`
- Forecast1MinTemp=`echo "$Forecast" | cut -f3 -d'|'`
- Forecast1MaxTemp=`echo "$Forecast" | cut -f4 -d'|'`
- if [ "$Forecast1MinTemp" -gt 0 ]; then
- Forecast1MinTemp="+$Forecast1MinTemp"
- else
- if [ "$Forecast1MaxTemp" -gt 0 ]; then
- Forecast1MaxTemp="+$Forecast1MaxTemp"
- fi
- fi
- Forecast2Day=`echo "$Forecast" | cut -f5 -d'|'`
- Forecast2Day=`DayToString "$Forecast2Day"`
- Forecast2Condition=`echo "$Forecast" | cut -f6 -d'|'`
- Forecast2ConditionImage="$Forecast2Condition.gif"
- if [ ! -f "$ImagesDir/$Forecast2Condition.gif" ]; then
- curl -s -o "$ImagesDir/$Forecast2Condition.gif" "http://l.yimg.com/a/i/us/we/52/$Forecast2ConditionImage"
- fi
- Forecast2Condition=`ConditionToString "$Forecast2Condition"`
- Forecast2MinTemp=`echo "$Forecast" | cut -f7 -d'|'`
- Forecast2MaxTemp=`echo "$Forecast" | cut -f8 -d'|'`
- if [ "$Forecast2MinTemp" -gt 0 ]; then
- Forecast2MinTemp="+$Forecast2MinTemp"
- else
- if [ "$Forecast2MaxTemp" -gt 0 ]; then
- Forecast2MaxTemp="+$Forecast2MaxTemp"
- fi
- fi
- echo '<div class="forecast-container"><ul id="forecast">
- <li><strong>'"$Forecast1Day"'</strong><br/>
- <h1><img style="vertical-align:middle;" src="data/weather1.gif" alt="" />'"$Forecast1MinTemp"' ... '"$Forecast1MaxTemp"'</h1>
- '"$Forecast1Condition"'</li>
- <li><strong>'"$Forecast2Day"'</strong><br/>
- <h1><img style="vertical-align:middle;" src="data/weather2.gif" alt="" />'"$Forecast2MinTemp"' ... '"$Forecast2MaxTemp"'</h1>
- '"$Forecast2Condition"'</li>
- </ul></div>'
- cp -f "$ImagesDir/$CurConditionImage" "/var/www/home-nadym.ru/data/weather.gif"
- cp -f "$ImagesDir/$Forecast1ConditionImage" "/var/www/home-nadym.ru/data/weather1.gif"
- cp -f "$ImagesDir/$Forecast2ConditionImage" "/var/www/home-nadym.ru/data/weather2.gif"
- echo "</div></div>"
- fi
Add Comment
Please, Sign In to add comment