config / .fgfs / fgcoderss /
8a7d39a 4 years ago
1 contributor
69 lines | 1.825kb
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70#!/bin/bash

source_path=${1:-"$HOME/scripts/flightgear/source"}

function xmlgetnext () {
    local IFS='>'
    read -d '<' TAG VALUE
    # by design, the first TAG/VALUE pair is empty
    # to avoid infinite loops at end of file parsing we return an error
    # the next time we find an empty TAG
    if test -z "$TAG"; then
        test ${xmlgetnext_firstentry:-1} -eq 1 && xmlgetnext_firstentry=0 || return 1;
    fi
    # process $TAG only if necessary
    local _TAG=$(printf '%q' $TAG)
    if test ${_TAG:0:1} = '$'; then
        TAG=$(tr '\n' ' ' <<< $TAG | sed 's/  */ /g; s/ *$//')
    fi
}

exit_trap () {
    rm $apixml
}

function showRSS () {
    echo -e "${1^^}\n${1//[[:alnum:]]/-}"
    revparse=$(git -C "$source_path/$1" rev-parse HEAD)
    wget -qO- https://sourceforge.net/p/flightgear/$1/feed | while xmlgetnext; do
        case "${TAG:0:1}" in
            ''|'?'|'!')
                continue;;
            /)
                property=${property%/*};;
            *)
                if test "${TAG: -1}" != '/'; then
                    property+=/${TAG%% *}
                fi;;
        esac

        case "$property" in
            '/rss/channel/item/title')
                title=$VALUE
                ;;
            '/rss/channel/item/link')
                sha1=${VALUE/https:\/\/sourceforge.net\/p\/flightgear\/${1}\/ci\/}
                ;;
            '/rss/channel/item/pubDate')
                pubDate=$(date +'%e %B' -d "$VALUE")
                ;;
        esac

        if test "$TAG" = "/item"; then
            if test $revparse/ = $sha1; then
                title="* ${title}"
            else
                title="  ${title}"
            fi
            echo "$title (${pubDate/# })"
        fi
    done
}

cat << EOF
$(showRSS simgear)

$(showRSS flightgear)

$(showRSS fgdata)
EOF