summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/sb-forecast
blob: dd997c854ffc92094ceb0615c5ff1c902c55692f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh

LOCATION=$(cat "$XDG_CONFIG_HOME/forecast/location")

main () {
    case "$1" in
        -b|--browser)
            xdg-open "https://wttr.in/$LOCATION"
            exit 0 ;;
    esac

    res=$(curl -sf wttr.in/"$LOCATION"?format="%x+%t") || exit 1

    icon=$(condition_icon "$res")
    temp=$(temperature "$res")
    echo "$icon" "$temp"
}

condition_icon () {
    icon=$(echo "$1" | cut -d\  -f1)

    case "$icon" in
        'mm') echo     ;; 
        '=') echo      ;;  
        '///') echo    ;;    
        '//') echo     ;;
        '**') echo     ;;
        '*/*') echo    ;;
        '/') echo      ;;
        '.') echo      ;;
        'x') echo      ;;
        'x/') echo     ;;
        '*') echo      ;;
        '*/') echo     ;;
        'm') echo      ;;
        'o') echo      ;;
        '/!/') echo    ;;
        '!/') echo     ;;
        '*!*') echo    ;;
        'mmm') echo    ;;
        *) echo ? ;;
    esac
}

temperature () {
    echo "$1" | cut -d\  -f2 | sed 's/+//' | sed 's/C//'
}

main "$@"