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