-
Notifications
You must be signed in to change notification settings - Fork 11
/
mfw
124 lines (99 loc) · 3.5 KB
/
mfw
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
#----------------------------------------------------------------------------------
# Project Name - miscellaneous/mfw (Mint Forum Watch)
# Started On - Sun 21 Jan 14:15:13 GMT 2018
# Last Change - Wed 31 Jan 12:46:40 GMT 2018
# Author E-Mail - terminalforlife@yahoo.com
# Author GitHub - https://github.com/terminalforlife
#----------------------------------------------------------------------------------
# As I frequent the Mint forums so often, in an effort to help people, it'd be
# helpful to me if I can be apprised of thread posts in the Newbie Questions
# forums. This small program does just that; designed to run in the background.
#
# At some point, I may introduce the ability to watch different forums.
#----------------------------------------------------------------------------------
XERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; exit 1; }
ERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; }
declare -i DEPCOUNT=0
for DEP in /bin/sleep /usr/bin/{notify-send,wget}; {
[ -x "$DEP" ] || {
ERR "$LINENO" "Dependency '$DEP' not met."
DEPCOUNT+=1
}
}
[ $DEPCOUNT -eq 0 ] || exit 1
USAGE(){
while read -r; do
printf "%s\n" "$REPLY"
done <<-EOF
MFW - Mint Forum Watch (31st January 2018)
Written by terminalforlife (terminalforlife@yahoo.com)
Notifier for page-one threads on the Newbie Questions Linux Mint forum.
SYNTAX: mfw [OPTS] [INTERVAL]
OPTS: --help|-h|-? - Displays this help information.
--debug|-D - Enables the built-in bash debugging.
--filter|-F ID - Omit threads by their ID number. (See URL)
--no-notify-wait - Display all notifications at once.
--run-once|-O - Don't run in the background; run only once.
EXAMPLE: mfw -F 12345 -F 54321 --no-notify-wait 30
NOTE: Where INTERVAL is the time between each check, in minutes.
SITE: https://forums.linuxmint.com
EOF
}
while [ "$1" ]; do
case "$1" in
--help|-h|-\?)
USAGE; exit 0 ;;
--debug|-D)
DEBUGME="true" ;;
--filter|-F)
shift; ID="$1" ;;
--no-notify-wait)
NO_NOTIFY_WAIT="true" ;;
--run-once|-O)
RUN_ONCE="true" ;;
-*)
XERR "$LINENO" "Incorrect argument(s) specified." ;;
*)
break ;;
esac
shift
done
INTERVAL="$1"
[ "$DEBUGME" == "true" ] && set -xeu
URL='https://forums.linuxmint.com/viewforum.php?f=90'
REGEX='\?f=90\&\;t=[0-9]+\&sid=[0-9a-z]+\"\sclass=\"topictitle\">.*<'
# Filter out the old standard, stickied threads, plus user specified threads.
FILTER=(83444 83314 81997 97158 245700 230142 219089 224270 $FILTER_ADD)
while :; do
PARSE(){
while IFS=">" read -a X; do
if [[ "${X[*]}" =~ class=\"posts\"\ [0-9]+\ \< ]]; then
T_REP="${X[1]//[!0-9]}"
[ $T_REP -eq 0 ] || continue
elif [[ "${X[*]}" =~ class=\"topictitle\" ]]; then
IFS=";" read -a Y <<< "${X[0]/*<a href=}"
T_ID="${Y[1]//[!0-9]}"
T_STR="${X[1]%</a}"
for Z in ${FILTER[@]}; {
[ "$Z" == "$T_ID" ] && continue 2
}
printf "%6d[%0.2d]: %s\n" "$T_ID" "$T_REP" "$T_STR"
fi
done <<< "$(/usr/bin/wget -q "$URL" -O -)"
}
while read -a R; do
BUF="${R/???????}"
if ! [ "$NO_NOTIFY_WAIT" == "true" ]; then
printf -v SECS "%0.5d" "$RANDOM"
/bin/sleep ${SECS%???}s
fi
/usr/bin/notify-send "${R[*]}"
done <<< "$(PARSE)"
if ! [ "$RUN_ONCE" == "true" ]; then
/bin/sleep ${INTERVAL}m
else
break
fi
done &
# vim: noexpandtab colorcolumn=84 tabstop=8 noswapfile nobackup