Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 328 lines (306 sloc) 12.199 kb
e921702 @ShadowKyogre Placing random scripts for sharing
authored
1 #!/bin/bash
2
3 #by ShadowKyogre (contact at shadowkyogre@aim.com or alternate email/IM if asked for)
4 #checks your dA messages for you
5 #TODO:add ability to use on multiple accounts?
6 #TODO:add ability to pick which one to notify and whether to display difference from last time to current
7 #TODO:add more options to output specific types
8 #TODO:output only diff
9 #TODO:MOAR DETAILED output per subtype
10 #TODO:grab icons?
11 #TODO:overlay # on each icon type?
12 #Please don't uncomment anything here yet!
13
14 #convert /home/shadowkyogre/.icons/Breathless/48x48/apps/3d.png -gravity southwest -stroke '#000C' -strokewidth 2 -annotate 0 '3' -stroke none -fill white -annotate 0 '3' outhere.png
15 #howto overlay numbers
16 USERNAME="$1"
17 PASSWORD="$2"
18 #checkInterval="hour" hour, month, day, or immediate
19 #makeIcons=0
20 #groupIcon="/path/to/file.png"
21 #watchlistIcon="/path/to/file.png"
22 #deviationIcon="/path/to/file.png"
23 #feedbackIcon="/path/to/file.png"
24 #notesIcon="/path/to/file.png"
25 #noticeIcon="/path/to/file.png"
26 #correspondenceIcon="/path/to/file.png"
27 #msgIcon="/path/to/file.png"
28 #numberFG='#YRCOLR'
29 #numberBG='#YRCOLR'
30 #grabFace="computer"
31
32 check(){
33 if [[ -e ~/.config/dAcheckrc ]];then
34 source ~/.config/dAcheckrc
35 else
36 touch ~/.config/dAcheckrc
37 if [[ -z "$USERNAME" || -z "$PASSWORD" ]];then
38 echo "Please put in your username and password for the first run"
39 echo "You could also fill out ~/.config/dAcheckrc like this:"
40 echo "USERNAME=\"yourusername\""
41 echo "PASSWORD=\"yourpassword\""
42 echo "clearCookies=0 #0 or 1"
43 exit 1
44 fi
45 echo "USERNAME=\"$USERNAME\"" > ~/.config/dAcheckrc
46 echo "PASSWORD=\"$PASSWORD\"" >> ~/.config/dAcheckrc
47 echo "clearCookies=0 #0 or 1" >> ~/.config/dAcheckrc
48 #echo "makeIcons=0 #0 or 1" >> ~/.config/dAcheckrc
49 echo "checkInterval=\"hour\" #hour, day, month, or immediate" >> ~/.config/dAcheckrc
50 clearCookies=0
51 #makeIcons=0
52 checkInterval="hour"
53 fi
54 }
55
56 clear(){
57 rm -f ~/.config/dAcheck.cjar
58 }
59
60 login(){
61 if (( $(ping google.com -c 3 > /dev/null;echo $?) != 0 ));then
62 echo "Your network is down."
63 exit 1
64 fi
65 if [[ -s ~/.config/dAcheck.cjar ]];then
66 if [[ "$(echo $(cat ~/.config/dAcheck.cjar))" == "" ]];then
67 rm -f ~/.config/dAcheck.cjar
68 curl -A "Mozilla/4.73 [[en] (X11; U; Linux 2.2.15 i686)" -s \
69 --cookie ~/.config/dAcheck.cjar --cookie-jar ~/.config/dAcheck.cjar \
70 --data-urlencode "username=$USERNAME" \
71 --data-urlencode "password=$PASSWORD" \
72 --data-urlencode "action=Login" \
73 --data "reusetoken=1" \
74 --location "https://www.deviantart.com/users/login" > /dev/null
75 fi
76 else
77 curl -A "Mozilla/4.73 [[en] (X11; U; Linux 2.2.15 i686)" -s \
78 --cookie ~/.config/dAcheck.cjar --cookie-jar ~/.config/dAcheck.cjar \
79 --data-urlencode "username=$USERNAME" \
80 --data-urlencode "password=$PASSWORD" \
81 --data-urlencode "action=Login" \
82 --data "reusetoken=1" \
83 --location "https://www.deviantart.com/users/login" > /dev/null
84 fi
85 TEMP_FILE="$(mktemp)"
86 curl -A "Mozilla/4.73 [[en] (X11; U; Linux 2.2.15 i686)" -s \
87 --cookie ~/.config/dAcheck.cjar --cookie-jar ~/.config/dAcheck.cjar \
88 --data "username=" \
89 --data "password=" \
90 --data "action=Login" \
91 --location "https://www.deviantart.com/users/login" -o "$TEMP_FILE"
92 }
93
94 retrieve(){
95 if [[ "$(grep "Unsplinter Menu" $TEMP_FILE -o)" == "Unsplinter Menu" ]];then
96 if [[ "$(grep "Group Message" $TEMP_FILE -o)" == "Group Messages" ]];then
97 thisGroup=$(grep -E --regexp='groups"><i class="i16"></i>[[1234567890, ]+<' $TEMP_FILE -o | \
98 sed 's|groups"><i class="i16"></i>||;s|<||;s|,||;s| ||g')
99 fi
100 thisdAwatch=$(grep -E --regexp='deviantwatch"><i class="icon i1"></i>.[[1234567890,]+<' $TEMP_FILE -o | \
101 sed 's|deviantwatch"><i class="icon i1"></i>||;s|<||;s|,||;s| ||g')
102 thisDeviations=$(grep -E --regexp='deviations"><i class="icon i1"></i>.[[1234567890,]+<' $TEMP_FILE -o | \
103 sed 's|deviations"><i class="icon i1"></i>||;s|<||;s|,||;s| ||g')
104 thisFeedback=$(grep -E --regexp='feedback"><i class="icon i2"></i>.[[1234567890,]+<' $TEMP_FILE -o | \
105 sed 's|feedback"><i class="icon i2"></i>||;s|<||;s|,||;s| ||g')
106 if [[ "$(grep correspondence $TEMP_FILE -o)" == "correspondence" ]];then
107 thisCorrespondence=$(grep -E --regexp='correspondence"><i class="icon i17"></i>.[[1234567890,]+<' $TEMP_FILE -o | \
108 sed 's|correspondence"><i class="icon i17"></i>||;s|<||;s|,||;s| ||g')
109 fi
110 thisNewNotes=$(grep -E --regexp='Notes"><i class="icon i9"></i>.[[1234567890,]+<' $TEMP_FILE -o | \
111 sed 's|Notes"><i class="icon i9"></i>||;s|<||;s|,||;s| ||g')
112 if [[ "$(grep notices $TEMP_FILE -o)" == "notices" ]];then
113 thisNotices=$(grep -E --regexp='notices"><i class="icon i3"></i>.[[1234567890,]+<' $TEMP_FILE -o | \
114 sed 's|notices"><i class="icon i3"></i>||;s|<||;s|,||;s| ||g')
115 fi
116 else
117 thisMsg=$(grep '<a class=oh-l href="http://my.deviantart.com/messages/"><i class="icon h-icon i3"></i> &nbsp;' $TEMP_FILE | \
118 sed 's|<a class=oh-l href="http://my.deviantart.com/messages/"><i class="icon h-icon i3"></i> &nbsp;||;s|,||' | \
119 sed 's|>||;s| <img src="https://s.deviantart.com/minish/main/radbelow.png" class=oh-mg width=11 height=11></a></div> <div class="oh-ml"||' | \
120 sed 's| ||')
121 fi
122 }
123
124 calculate(){
125 if [[ -e ~/.config/dAcheck.msg ]];then
126 source ~/.config/dAcheck.msg
127 else
128 touch ~/.config/dAcheck.msg
129 fi
130 if [[ "$(grep "Unsplinter Menu" $TEMP_FILE -o)" == "Unsplinter Menu" ]];then
131 if [[ "$(grep "Group Message" $TEMP_FILE -o)" == "Group Messages" ]];then
132 if (( $prevGroup < $thisGroup ));then
133 diffGroup=$(($thisGroup - ${prevGroup:=$thisGroup}))
134 else
135 diffGroup=$((${prevGroup:=$thisGroup} - $thisGroup))
136 fi
137 fi
138 if [[ $thisdAwatch -eq 0 ]];then
139 diffdAwatch=0
140 elif (( ${prevdAwatch:-0} < $thisdAwatch ));then
141 diffdAwatch=$(($thisdAwatch - ${prevdAwatch:=$thisdAwatch}))
142 else
143 diffdAwatch=$((${prevdAwatch:=$thisdAwatch} - $thisdAwatch))
144 fi
145
146 if [[ $thisDeviations -eq 0 ]];then
147 diffDeviations=0
148 elif (( ${prevDeviations:-0} < $thisDeviations ));then
149 diffDeviations=$(($thisDeviations - ${prevDeviations:=$thisDeviations}))
150 else
151 diffDeviations=$((${prevDeviations:=$thisDeviations} - $thisDeviations))
152 fi
153
154 if [[ $thisFeedback -eq 0 ]];then
155 diffFeedback=0
156 elif (( ${prevFeedback:-0} < $thisFeedback ));then
157 diffFeedback=$(($thisFeedback - ${prevFeedback:=$thisFeedback}))
158 else
159 diffFeedback=$((${prevFeedback:=$thisFeedback} - $thisFeedback))
160 fi
161
162 if [[ "$(grep correspondence $TEMP_FILE -o)" == "correspondence" ]];then
163 if (( ${prevCorrespondence:-0} < $thisCorrespondence ));then
164 diffCorrespondence=$(($thisCorrespondence - ${prevCorrespondence:=$thisCorrespondence}))
165 else
166 diffCorrespondence=$((${prevCorrespondence:=$thisCorrespondence} - $thisCorrespondence))
167 fi
168 fi
169
170 if [[ $thisNewNotes -eq 0 ]];then
171 diffNewNotes=0
172 elif (( ${prevNewNotes:-0} < $thisNewNotes ));then
173 diffNewNotes=$(($thisNewNotes - ${prevNewNotes:=$thisNewNotes}))
174 else
175 diffNewNotes=$((${prevNewNotes:=$thisNewNotes} - $thisNewNotes))
176 fi
177
178 if [[ "$(grep notices $TEMP_FILE -o)" == "notices" ]];then
179 if (( ${prevNotices:-0} < $thisNotices ));then
180 diffNotices=$(($thisNotices - ${prevNotices:=$thisNotices}))
181 else
182 diffNotices=$((${prevNotices:=$thisNotices} - $thisNotices))
183 fi
184 fi
185 else
186 if [[ $this2Msg -eq 0 ]];then
187 diffMsg=0
188 elif (( ${prevMsg:-0} < $thisMsg ));then
189 diffMsg=$(($thisMsg - ${prevMsg:=$thisMsg}))
190 else
191 diffMsg=$((${prevMsg:=$thisMsg} - $thisMsg))
192 fi
193 fi
194 }
195
196 display(){
197 if [[ "$(grep "Unsplinter Menu" $TEMP_FILE -o)" == "Unsplinter Menu" ]];then
198 if [[ "$(grep "Group Message" $TEMP_FILE -o)" == "Group Messages" ]];then
199 if (( $prevGroup < $thisGroup ));then
200 echo "$thisGroup group message(s), $diffGroup new message(s)"
201 else
202 echo "$thisGroup group message(s), $diffGroup message(s) deleted"
203 fi
204 fi
205 if [[ $thisdAwatch -eq 0 ]];then
206 echo "No messages from your watchlist"
207 elif (( ${prevdAwatch:-0} < $thisdAwatch )) || [[ $diffdAwatch -eq 0 ]];then
208 echo "$thisdAwatch watchlist message(s), $diffdAwatch new message(s)"
209 else
210 echo "$thisdAwatch watchlist message(s), $diffdAwatch message(s) deleted"
211 fi
212
213 if [[ $thisDeviations -eq 0 ]];then
214 echo "No watched deviations"
215 elif (( ${prevDeviations:-0} < $thisDeviations )) || [[ $diffDeviations -eq 0 ]];then
216 echo "$thisDeviations watched deviations(s), $diffDeviations new deviation(s)"
217 else
218 echo "$thisDeviations watched deviation(s), $diffDeviations deviation(s) deleted"
219 fi
220
221 if [[ $thisFeedback -eq 0 ]];then
222 echo "No feedback"
223 elif (( ${prevFeedback:-0} < $thisFeedback )) || [[ $diffFeedback -eq 0 ]];then
224 echo "$thisFeedback feedback, $diffFeedback new feedback"
225 else
226 echo "$thisFeedback feedback, $diffFeedback feedback deleted"
227 fi
228
229 if [[ "$(grep correspondence $TEMP_FILE -o)" == "correspondence" ]];then
230 if (( ${prevCorrespondence:-0} < $thisCorrespondence ));then
231 echo "$thisCorrespondence correspondence(s), $diffCorrespondence new correspondence(s)"
232 else
233 echo "$thisCorrespondence watched correspondence(s), $diffCorrespondence correspondence(s) deleted"
234 fi
235 fi
236
237 if [[ $thisNewNotes -eq 0 ]];then
238 echo "No unread notes"
239 elif (( ${prevNewNotes:-0} < $thisNewNotes )) || [[ $diffNotes -eq 0 ]];then
240 echo "$thisNewNotes unread note(s), $diffNewNotes new unread note(s)"
241 else
242 echo "$thisNewNotes unread note(s), $diffNewNotes unread note(s) deleted"
243 fi
244
245 if [[ "$(grep notices $TEMP_FILE -o)" == "notices" ]];then
246 if (( ${prevNotices:-0} < $thisNotices ));then
247 echo "$thisNotices notice(s), $diffNotices new notices(s)"
248 else
249 echo "$thisNotices notices(s), $diffNotices notices(s) deleted"
250 fi
251 fi
252 else
253 if [[ $this2Msg -eq 0 ]];then
254 echo "No messages"
255 elif (( ${prevMsg:-0} < $thisMsg )) || [[ $diffMsg -eq 0 ]];then
256 echo "$thisMsg message(s), $diffMsg new message(s)"
257 else
258 echo "$thisMsg message(s), $diffMsg new message(s) deleted"
259 fi
260 fi
261 }
262
263 settings(){
264 echo -n "" > ~/.config/dAcheck.msg
265 if [[ "$(grep "Unsplinter Menu" $TEMP_FILE -o)" == "Unsplinter Menu" ]];then
266 if [[ "$(grep "Group Message" $TEMP_FILE -o)" == "Group Messages" ]];then
267 echo "prevGroup=$thisGroup" >> ~/.config/dAcheck.msg
268 fi
269 echo "prevdAwatch=$thisdAwatch" >> ~/.config/dAcheck.msg
270 echo "prevDeviations=$thisDeviations" >> ~/.config/dAcheck.msg
271 echo "prevFeedback=$thisFeedback" >> ~/.config/dAcheck.msg
272 if [[ "$(grep correspondence $TEMP_FILE -o)" == "correspondence" ]];then
273 echo "prevCorrespondence=$thisCorrespondence" >> ~/.config/dAcheck.msg
274 fi
275 echo "prevNewNotes=$thisNewNotes" >> ~/.config/dAcheck.msg
276 if [[ "$(grep notices $TEMP_FILE -o)" == "notices" ]];then
277 echo "prevNotices=$thisNotices" >> ~/.config/dAcheck.msg
278 fi
279 else
280 echo "prevMsg=$thisMsg" >> ~/.config/dAcheck.msg
281 fi
282 sed -i 's| ||g' ~/.config/dAcheck.msg
283 }
284
285 check
286 if [[ $clearCookies -eq 1 ]];then
287 clear
288 fi
289 login
290 if [ -z $symbol ];then
291 echo "symbol=\"$(grep -E 'symbol":"."' -m 1 -o $TEMP_FILE|sed 's|symbol":"\(.\)"|\1|')\" #THIS IS AUTOWRITTEN. PLEASE DO NOT EDIT THIS" >> ~/.config/dAcheckrc
292 fi
293 retrieve
294 calculate
295 #TODO: force update of prev variables once it detects a deletion
296 display
297 #only export prev immediately if the interval is set to immediate
298 case $checkInterval in
299 "hour")
300 if (( $(date +%k)-${lastCheck:-0} > 0 ));then
301 settings
302 echo "lastCheck=$(date +%k)" >> ~/.config/dAcheck.msg
303 fi
304 ;;
305 "month")
306 if (( $(date +%m)-${lastCheck:-0} > 0 ));then
307 settings
308 echo "lastCheck=$(date +%m)" >> ~/.config/dAcheck.msg
309 fi
310 ;;
311 "day")
312 if (( (($(date +%d)-${lastCheck:-0})) > 0 ));then
313 settings
314 echo "lastCheck=$(date +%d)" >> ~/.config/dAcheck.msg
315 fi
316 ;;
317 "immediate")
318 settings
319 ;;
320 esac
321 rm -f $TEMP_FILE
322
323 #urpage=$(echo http:\/\/$(echo $|sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/).deviantart.com)
324 #<a href="http://shadowkyogre.deviantart.com/"><img title="shadowkyogre" alt=":iconshadowkyogre:" src="http://a.deviantart.net/avatars/s/h/shadowkyogre.gif?2" style="float: left; margin-right: 2px; margin-bottom: 2px;" class="avatar"></a>
325 #avatar=$(curl -A "Mozilla/4.73 [[en] (X11; U; Linux 2.2.15 i686)" -s $urpage|grep avatar|grep $(echo $USERNAME|y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/) -m 1|sed 's|<link href="||;s|\?." rel="apple-touch-icon"/>||')
326 #wget $avatar -o
327 #this is for possibly avatar synching on your pc and account
Something went wrong with that request. Please try again.