Czy można to jakoś zmienić?
Dorzucam plik pogodynka.utf8
Kod: Zaznacz cały
#!/bin/sh
## Default config file:
CONFIGFILE="${HOME}/Conky/pogodynka.utf8"
## Default browser (currently w3m, elinks, links, link2 and lynx are supported)
BROWSER=w3m
## Default location code
CODE="PLXX0031"
## Output format, available variables:
## %STATE Cast in english
## %STATEPL Cast in polish
## %TEMP Temperature
## %FTEMP Fells like temperature
## %PRSSR Pressure
## %WIND Direction, speed of wind
## %HMDT Humidity
## %SUNRS Sunrise
## %SUNST Sunset
## %ICON Weather icon for conky (weather.ttf needed)
## %TEMPICON Temperature icon
## Use '\n' to brake line
FORMAT="%STATEPL\nTemperature: %TEMP"
## Low and high temperatures for low/medium/high temperature icons
LOWTEMP=5
HITEMP=25
## Which temperature scale you want to use?
## set SCALE to 'C' to use Celsius scale or
## to 'F' to use Fahrenheit scale
SCALE='C'
## Flags
while [ ! -z ${1} ]; do
case $1 in
## Halp! (No, it's not typo. It's my tribute to I Can Has Cheezburger)
'-h') cat <<EOF
pogodynka 0.4
http://pogodynka.fluxboxpl.org
Usage:
-h this help
-c code weather cast for entered code
-C config alternative config file
-l list builtin locations (polish only)
location weather cast for entered location (polish only)
EOF
exit
;;
## List locations
'-l') cat <<EOF
Available locations:
bialystok olesnica
brzeg otwock
chojnice plock
czestochowa police
elblag poznan
gdansk pruszkow
gdynia przemysl
goleniow rybnik
gorzow_wlkp siedlce
hel sopot
kalisz sosnowiec
katowice swinoujscie
ketrzyn szczecin
kielce tarnow
klodzko torun
kolobrzeg tychy
koszalin warszawa
krakow wroclaw
leba zabrze
legnica zamosc
lodz zielona_gora
lublin
lublin_radawiec zatoka_pomorska
malczyce poludniowy_baltyk
mlawa sniezka
EOF
exit
;;
## location code from variables
'bialystok') shift 1 && FORCECODE='PLXX0038' ;;
'brzeg') shift 1 && FORCECODE='PLXX0001' ;;
'chojnice') shift 1 && FORCECODE='PLXX0035' ;;
'czestochowa') shift 1 && FORCECODE='PLXX0002' ;;
'elblag') shift 1 && FORCECODE='PLXX0004' ;;
'gdansk') shift 1 && FORCECODE='PLXX0005' ;;
'gdynia') shift 1 && FORCECODE='PLXX0006' ;;
'goleniow') shift 1 && FORCECODE='PLXX0007' ;;
'gorzow_wlkp') shift 1 && FORCECODE='PLXX0008' ;;
'hel') shift 1 && FORCECODE='PLXX0033' ;;
'kalisz') shift 1 && FORCECODE='PLXX0009' ;;
'katowice') shift 1 && FORCECODE='PLXX0010' ;;
'ketrzyn') shift 1 && FORCECODE='PLXX0055' ;;
'kielce') shift 1 && FORCECODE='PLXX0011' ;;
'klodzko') shift 1 && FORCECODE='PLXX0047' ;;
'kolobrzeg') shift 1 && FORCECODE='PLXX0054' ;;
'koszalin') shift 1 && FORCECODE='PLXX0031' ;;
'krakow') shift 1 && FORCECODE='PLXX0012' ;;
'leba') shift 1 && FORCECODE='PLXX0032' ;;
'legnica') shift 1 && FORCECODE='PLXX0013' ;;
'lodz') shift 1 && FORCECODE='PLXX0014' ;;
'lublin') shift 1 && FORCECODE='PLXX0049' ;;
'lublin_radawiec') shift 1 && FORCECODE='PLXX0045' ;;
'malczyce') shift 1 && FORCECODE='PLXX0015' ;;
'mlawa') shift 1 && FORCECODE='PLXX0037' ;;
'olesnica') shift 1 && FORCECODE='PLXX0016' ;;
'otwock') shift 1 && FORCECODE='PLXX0017' ;;
'plock') shift 1 && FORCECODE='PLXX0018' ;;
'police') shift 1 && FORCECODE='PLXX0019' ;;
'poznan') shift 1 && FORCECODE='PLXX0040' ;;
'pruszkow') shift 1 && FORCECODE='PLXX0020' ;;
'przemysl') shift 1 && FORCECODE='PLXX0050' ;;
'rybnik') shift 1 && FORCECODE='PLXX0021' ;;
'siedlce') shift 1 && FORCECODE='PLXX0042' ;;
'sopot') shift 1 && FORCECODE='PLXX0053' ;;
'sosnowiec') shift 1 && FORCECODE='PLXX0022' ;;
'swinoujscie') shift 1 && FORCECODE='PLXX0024' ;;
'szczecin') shift 1 && FORCECODE='PLXX0025' ;;
'tarnow') shift 1 && FORCECODE='PLXX0026' ;;
'torun') shift 1 && FORCECODE='PLXX0036' ;;
'tychy') shift 1 && FORCECODE='PLXX0027' ;;
'warszawa') shift 1 && FORCECODE='PLXX0028' ;;
'wroclaw') shift 1 && FORCECODE='PLXX0029' ;;
'zabrze') shift 1 && FORCECODE='PLXX0030' ;;
'zamosc') shift 1 && FORCECODE='PLXX0048' ;;
'zielona_gora') shift 1 && FORCECODE='PLXX0043' ;;
'zatoka_pomorska') shift 1 && FORCECODE='PLXX0051' ;;
'poludniowy_baltyk') shift 1 && FORCECODE='PLXX0052' ;;
'sniezka') shift 1 && FORCECODE='PLXX0046' ;;
## Weather cast for entered code
'-c')
shift 1
if [ ! -z "$1" ] && ! echo "$1" | grep -E "^-" >/dev/null 2>&1; then
FORCECODE="$1"
shift 1
else
cat <<EOF
$0: option \`-c' requires an argument
Try \`$0 -h' for more information.
EOF
exit 1
fi
;;
## Alternative config file
'-C')
shift 1
if [ ! -z "$1" ] && ! echo "$1" | grep -E "^-" >/dev/null 2>&1; then
CONFIGFILE="$1"
shift 1
else
cat <<EOF
$0: option \`-C' requires an argument
Try \`$0 -h' for more information.
EOF
exit 1
fi
;;
## None of above -> error
*)
cat <<EOF
$0: unrecognized option \`$*'
Try \`$0 -h' for more information.
EOF
exit 1
;;
esac
done
## Read variables from config, if exists and is readable
## thanks urug for this awk :)
if [ -r ${CONFIGFILE} ]; then
eval $(awk -F'=' '/.+=.+/{
if ( $1 == "CODE" ||
$1 == "FORMAT" ||
$1 == "ICONSIZE" ||
$1 == "BROWSER" ||
$1 == "LOWTEMP" ||
$1 == "HITEMP" ||
$1 == "SCALE" )
print $1 "=" $2 }' ${CONFIGFILE})
fi
[ -z $FORCECODE ] || CODE=$FORCECODE
## check if weather server is available
if ! ping -c1 weather.yahoo.com >/dev/null 2>&1; then
## It's not, finish
echo 'Service not available'
exit 1;
fi
## It is, fetch weather cast
## but first check if $BROWSER and $CODE are correct and exists
if [ "$BROWSER" != 'w3m' ] && [ "$BROWSER" != 'elinks' ] && [ "$BROWSER" != 'links2' ] && \
[ "$BROWSER" != 'links' ] && [ "$BROWSER" != 'lynx' ]; then
cat <<EOF
$0: unsupported BROWSER \`$BROWSER'
Please set correct value in $CONFIGFILE
(currently w3m, elinks, links, links2 and lynx are supported).
EOF
exit 1;
fi
if ! which "$BROWSER" >/dev/null 2>&1; then
cat <<EOF
$0: command not found \`$BROWSER'
Install $BROWSER or set other value for BROWSER in $CONFIGFILE
(currently w3m, elinks, links, links2 and lynx are supported).
EOF
exit 1;
fi
if ! echo "$CODE" | egrep "^[A-Z]{4}[0-9]{4}$" >/dev/null 2>&1; then
cat <<EOF
$0: unsupported location code \`$CODE'
Please set correct code in $CONFIGFILE (or use '-c CODE' or 'location' as an argument).
You can find your location on weather.yahoo.com, it is part of URL i.e. PLXX0028 in
http://weather.yahoo.com/forecast/PLXX0031_c.html
EOF
exit 1;
fi
if [ $SCALE != 'C' ] && [ $SCALE != 'F' ]; then
cat <<EOF
$0: unsupported scale code \`$SCALE'
Use 'C' for Celsius scale or 'F' for Fahrenheit scale.
EOF
exit 1;
fi
[ $SCALE = 'C' ] && WWWSUFIX='_c' || WWWSUFIX=''
FILE=/tmp/pogodynka.tmp
$BROWSER -dump "http://weather.yahoo.com/forecast/${CODE}${WWWSUFIX}.html" | \
sed -re '/^(\s+)?$/d;s/^(\s+)(.*)/\2/g;s/DEG/°/g' | grep -A18 'Current' > $FILE
## thanks Minio for part of this sed
## Set Variables
STATE=$(sed -n '2p' $FILE) # Cast in english
TEMP=$(tail -n1 $FILE | sed "s/°/°${SCALE}/g") # Temperature
FTEMP=$(sed -n '4p' $FILE | sed "s/°/°${SCALE}/g") # Feels like temperature
PRSSR=$(sed -n '6p' $FILE | awk '{print $1"hPa"}') # Pressure
WIND=$(sed -n '14p' $FILE) # Driection and speed of wind
HMDT=$(sed -n '8p' $FILE) # Humidity
SUNRS=$(sed -ne 's: am::g;16p' $FILE) # Sunrise
SUNST=$(sed -ne 's: pm::g;18p' $FILE |\
awk -F ':' '{print $1+12":"$2}') # Sunset
SUNRSM=$(echo $SUNRS | awk -F ':' '{print $1*60+$2}') # Sunrise minute (night or day?)
SUNSTM=$(echo $SUNST | awk -F ':' '{print $1*60+$2}') # Sunset minute (night or day?)
CURM=$(date +%R | awk -F ':' '{print $1*60+$2}') # Current minute (night or day?)
## Translate weather casts to polish (STATEPL)
## and set icon symbol
seticonsymbol() {
if [ $CURM -gt $SUNRSM ] && [ $CURM -lt $SUNSTM ]; then
ICON=$1 # It's day, set first symbol as icon
else
ICON=$2 # It's night, set second symbol as icon
fi
}
## Set icon symbol
[ -z $ICONSIZE ] && WEATHERFONT="weather" || WEATHERFONT="weather:size=$ICONSIZE"
TEMP2=$(echo "$TEMP" | sed "s/°${SCALE}//g") # Temperature without '°C' or '°F'
if [ $TEMP2 -gt $HITEMP ]; then
TEMPICON=z
elif [ $TEMP2 -lt $LOWTEMP ]; then
TEMPICON=x
else
TEMPICON=y
fi
## Transform FORMAT
FORMAT2=$(echo "$FORMAT" | \
sed "s/%STATEPL/$STATEPL/g;\
s/%STATE/$STATE/g;\
s/%TEMPICON/\${font $WEATHERFONT}$TEMPICON\${font}/g;\
s/%FTEMP/$FTEMP/g;\
s/%TEMP/$TEMP/g;\
s/%PRSSR/$PRSSR/g;\
s/%WIND/$WIND/g;\
s/%HMDT/$HMDT/g;\
s/%SUNRS/$SUNRS/g;\
s/%SUNST/$SUNST/g;\
s/%ICON/\${font $WEATHERFONT}$ICON\${font}/g")
## Return weather cast and remove temporary file
printf "$FORMAT2\n"
rm -f $FILE