Skip to content

Instantly share code, notes, and snippets.

@isoraqathedh
Created July 26, 2017 13:44
Show Gist options
  • Select an option

  • Save isoraqathedh/dfe306b0deaadd561fa530bcb86abccf to your computer and use it in GitHub Desktop.

Select an option

Save isoraqathedh/dfe306b0deaadd561fa530bcb86abccf to your computer and use it in GitHub Desktop.
Reddit Karma Printer (+ coloured deltas)
#!/bin/zsh
here=$(dirname ${(%):-%N})
case $BLOCK_BUTTON in
1)
sed -i -n '2p;2p' $here/cache.conf;;
4)
i3-msg 'workspace prev_on_output'
exit 1
;;
5)
i3-msg 'workspace next_on_output'
exit 1
;;
esac
read oldLink oldComment newLink newComment <<EOF
$(xargs < $here/cache.conf)
EOF
greenNumber="<span foreground='#00FF00'>~:d</span>"
redNumber="<span foreground='#FF0000'>~:d</span>"
if ((newLink > oldLink + 5)); then
linkSwitch=1
elif ((newLink < oldLink - 5)); then
linkSwitch=2
else
linkSwitch=0
fi
if ((newComment > oldComment + 5)); then
commentSwitch=1
elif ((newComment < oldComment - 5)); then
commentSwitch=2
else
commentSwitch=0
fi
sbcl --noinform --no-userinit --no-sysinit --non-interactive --eval "
(format t \"P ~[~:d~;$greenNumber~;$redNumber~] ~
C ~[~:d~;$greenNumber~;$redNumber~]~%\"
$linkSwitch $newLink $commentSwitch $newComment)"
#!/usr/local/bin/sbcl --script
(load "~/quicklisp/setup.lisp")
(ql:quickload '(:yason :drakma) :silent t)
(with-open-file (s (make-pathname :name "cache"
:type "conf"
:defaults *load-pathname*)
:if-exists :overwrite
:if-does-not-exist :create
:direction :io)
(let* ((drakma:*text-content-types* `(("application" . "json")
("text" . "json")
,@drakma:*text-content-types*))
(data (cdr
(assoc
"data"
(yason:parse
(drakma:http-request
(format nil
"https://www.reddit.com/user/~a/about.json"
"isoraqathedh")
:user-agent "i3blocks Karmafetcher")
:object-as :alist)
:test #'string=)))
(link-karma (cdr (assoc "link_karma" data :test #'string=)))
(comment-karma (cdr (assoc "comment_karma" data :test #'string=))))
(unless (read-line s nil)
(format s "~d ~d~%" link-karma comment-karma))
(format s "~d ~d~%" link-karma comment-karma)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment