examples/followdiff
author Mikael Berthe <mikael@lilotux.net>
Thu, 22 Sep 2022 16:32:45 +0200
changeset 261 270cc4dda0c5
parent 34 c604b1c786fd
permissions -rwxr-xr-x
Change version to 2.4.0-dev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
#! /bin/bash
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
# (Using bash or zsh for the <() process substitution feature...)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
#
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
# Sample script using madonctl (0.4+), use --help for usage.
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
# This script uses the 'combine' utility (from the moreutils package in
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
# Debian).
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
#
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
# MiKael, 2017-04
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
set -e
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
usage() {
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
    echo "Usage: $0 following_only|followers_only|both"
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
}
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
# Check madonctl is in the PATH
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
command -v madonctl >/dev/null 2>&1 || {
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
    echo "Error: madonctl not found">&2
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
    exit 1
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    20
}
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    21
# Check combine command (from the moreutils package)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    22
command -v combine >/dev/null 2>&1  || {
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
    echo "Error: combine not found">&2
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    24
    exit 1
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
}
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
# Get our account ID (not needed anymore as of 0.4.0)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
# me="$(madonctl account show --template '{{.id}}')"
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    29
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    30
# $1 = following/followers
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    31
getAccountFollow() {
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    32
    TEMPL='{{.id}}{{"\n"}}'
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    33
    madonctl accounts --all "$1" --template "$TEMPL"
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    34
}
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    36
displayAccount() {
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
    id=$1
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    38
    madonctl account show --account-id "$id" \
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    39
        --template '{{printf "%s\t%s\n" .acct .display_name}}'
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
}
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    41
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    42
combineOutput() {
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    43
    case $1 in
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    44
        (both)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    45
            combine <(getAccountFollow following) and <(getAccountFollow followers)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    46
            ;;
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    47
        (following_only)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    48
            combine <(getAccountFollow following) not <(getAccountFollow followers)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    49
            ;;
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
        (followers_only)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
            combine <(getAccountFollow followers) not <(getAccountFollow following)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    52
            ;;
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    53
    esac
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    54
}
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    55
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    56
case $1 in
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    57
    (both|following_only|followers_only)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    58
        combineOutput "$1" | while read acccountID; do
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    59
            displayAccount "$acccountID"
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    60
        done
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
        ;;
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    62
    (help|--help|-h)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    63
        usage
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    64
        ;;
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    65
    (*)
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    66
        usage>&2
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    67
        exit 1
c604b1c786fd Add shell script example
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    68
esac