#!/bin/bash
# coding: utf-8

### todo

# ARRAY wcode: Weather Code for font conkyWeather.ttf
# ARRAY wstr: Weather string text, 如：晴，雨

declare -a wcode wstr
declare -i AID

## AID: max array id 
AID="${#wcode[@]}"
let "AID -= 1"

#for a in `seq 0 "$AID"`; do
for a in 0 2 3; do
  case "${wcode[a]}" in
    0)wcode[a]="a" wstr[a]="晴" ;; 
    1)wcode[a]="e" wstr[a]="多云" ;;
    2)wcode[a]="f" wstr[a]="阴" ;; 
    3 | 33)wcode[a]="g" wstr[a]="阵雨" ;; 
    4)wcode[a]="k" wstr[a]="雷阵雨" ;; 

    7)wcode[a]="s" wstr[a]="小雨" ;; 
    8)wcode[a]="g" wstr[a]="雨" ;; 
    14)wcode[a]="o" wstr[a]="小雪" ;;           

## fuzzy wcode
    6)wcode[a]="p" wstr[a]="雨夹雪" ;; 
    13)wcode[a]="p" wstr[a]="阵雪" ;; 
    
    *)wcode[a]=" " wstr[a]="" ;;  
    
    # todo
    x)wcode[a]="r" wstr[a]="大到暴雪" ;;  
    x)wcode[a]="r" wstr[a]="暴雪" ;;
    x)wcode[a]="q" wstr[a]="中到大雪" ;;
    x)wcode[a]="p" wstr[a]="小到中雪" ;;
    x)wcode[a]="p" wstr[a]="中雪" ;;
    
    x)wcode[a]="l" wstr[a]="雷雨" ;;
    x)wcode[a]="j" wstr[a]="大到暴雨" ;;
    x)wcode[a]="j" wstr[a]="暴雨" ;;
    x)wcode[a]="i" wstr[a]="中到大雨" ;;
    x)wcode[a]="i" wstr[a]="大雨" ;;
    x)wcode[a]="h" wstr[a]="小到中雨" ;;
    x)wcode[a]="h" wstr[a]="中雨" ;;
    
    x)wcode[a]="u" wstr[a]="雾" ;;
    *)wcode[a]=" " wstr[a]="" ;;  
        
    # for font Arrow.ttf
    x)wcode[a]="v" wstr[a]="无持续风向" ;;
    x)wcode[a]="v" wstr[a]="旋转风" ;;

    x)wcode[a]="g" wstr[a]="西北风" ;;
    x)wcode[a]="c" wstr[a]="西南风" ;;
    x)wcode[a]="k" wstr[a]="东北风" ;;
    x)wcode[a]="o" wstr[a]="东南风" ;;
    
    x)wcode[a]="a" wstr[a]="南风" ;;
    x)wcode[a]="e" wstr[a]="西风" ;;
    x)wcode[a]="i" wstr[a]="北风" ;;
    x)wcode[a]="m" wstr[a]="东风" ;;

    *)wcode[a]=" " wstr[a]="" ;;        
      esac
    
    echo "${wcode[a]}" >> "$WEATHER_CODE"
 done
}

#
_show_conkyWeather_map () {
cat<<EOF
${voffset 0}${font ConkyWeather:style=Bold:size=18}${color0}${voffset -10}${execi 600 sed  's/^.*"img_title_single":"//' /tmp/forcast | sed 's/",".*$//' | sed 's/大到暴雪/r/;t w-0;s/暴雪/r/;t w-0;s/中到大雪/q/;t w-0;s/大雪/q/;t w-0;s/小到中雪/p/;t w-0;s/中雪/p/;t w-0;s/小雪/o/;t w-0;s/雷雨/l/;t w-0;s/雷阵雨/k/;t w-0;s/大到暴雨/j/;t w-0;s/暴雨/j/;t w-0;s/中到大雨/i/;t w-0;s/大雨/i/;t w-0;s/小到中雨/h/;t w-0;s/中雨/h/;t w-0;s/小雨/s/;t w-0;s/阵雨/g/;t w-0;s/阴/f/;t w-0;s/多云/e/;t w-0;s/雾/u/;t w-0;s/晴/a/;t w-0;s/转//;t w-0;:w-0;'}${color}${font}
${goto 105}${voffset -15}${font Arrows:style=Bold:size=18}${color0}${voffset -10}${execi 600 sed  's/^.*"WD":"//' /tmp/current | sed 's/",".*$//' | sed 's/无持续风向/v/;t w-0;s/旋转风/v/;t w-0;s/西北风/g/;t w-0;s/西南风/c/;s/东北风/k/;t w-0;s/东南风/o/;t w-0;t w-0;s/南风/a/;t w-0;s/西风/e/;t w-0;s/北风/i/;t w-0;s/东风/m/;t w-0;s/转//;t w-0;:w-0;'}${color}${font}
EOF
}