Last active
February 19, 2016 09:30
-
-
Save hirthwork/8502cd6f83157c600816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
function usage() { | |
>&$2 echo -e "Usage: $1 <cookie> <user> [<since>]\nExample:" | |
>&$2 echo -e "\t$1 user=f25bf40e0bc05d002b407a53bb76c63ee20ef8f8 hirthwork 'week ago'" | |
} | |
if [ "$1" = --help ] | |
then | |
usage $0 1 | |
exit 0 | |
elif [ -z $1 -o -z $2 ] | |
then | |
usage $0 2 | |
exit 1 | |
fi | |
if [ -z $3 ] | |
then | |
since='week ago' | |
else | |
since=$3 | |
fi | |
since=$(date +%s -d $since) | |
declare -A comments | |
before=0 | |
posts=0 | |
while : | |
do | |
data=$(curl -H "Cookie: $1" -s "http://point.im/api/blog/$2?before=$before" | jq -c '.posts[] | {uid: .uid | tostring, created:.post.created, id:.post.id, author:.post.author.login}' | tr '"' ' ' | tr -d ,) | |
if [ -z "$data" ] | |
then | |
break | |
fi | |
echo $data | awk '{if (tolower($13) == tolower("'$2'")){print $7" "$10}}' | while read date id | |
do | |
size=0 | |
echo -n "Requesting post #$id written at $date... " | |
curl -H "Cookie: $1" -s "http://point.im/api/post/$id" | jq '.comments[].author.login' | tr -d '"' | tr 'A-Z' 'a-z' | while read fox | |
do | |
((++comments[$fox])) | |
((++total)) | |
((++size)) | |
done | |
((++posts)) | |
echo Comments count: $size | |
sleep 1 | |
done | |
echo $data|tail -n1| read _ _ _ before _ _ date _ | |
date=$(date +%s -d $date) | |
if [ $date -lt $since ] | |
then | |
break | |
fi | |
done | |
echo | |
echo Total comments: $total, posts: $posts, foxes: ${#comments} | |
echo | |
for key in ${(@k)comments} | |
do | |
echo $key ${comments[$key]} | |
done | sort -n -r -k 2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment