Skip to content

Instantly share code, notes, and snippets.

@ilatypov
Last active August 4, 2018 19:16
Show Gist options
  • Save ilatypov/d3cc073ac828a9922a24280c4678b4cd to your computer and use it in GitHub Desktop.
Save ilatypov/d3cc073ac828a9922a24280c4678b4cd to your computer and use it in GitHub Desktop.
#! /bin/bash
function usage() {
cat >&2 <<EOT
Usage:
$ $0 USER_ID [-a PREVIOUS_COMMENT_ID] [-l LIMIT] [-p] [TEST]
e.g,
$ $0 10556300003468 -a 9674100014926 "justin|wynne|liberal|putin|trump|russia|petersburg|moscow"
[...]
"On and on. One persistent blunder after another. Well played Liberals!"
"Liberals - INGSOC"
"Is Mr. Atwal a paid Liberal Party member or one of those freebies?"
"Philllipines - Disaster China - Disaster India - Disaster. Justin - Disaster!"
"@Andy Doung \n\nYou're a typical Liberal shill, shilling for votes."
"@Robert Anderson \n\nThe point being, Justin is an inept dilettante."
"@Larry Ben \n\nDonald Trump is more popular than Kathleen Wynne."
"Liberal shills, shilling for votes."
"@Lars Persson \n\nLiberals represent a decline of the male species."
"Liberal shills doing what they do best. Shilling for votes."
"@Jake Holliston \n\nOntario has $21,000 Debt for every man, woman and child. Thank you Liberals!"
"@rhea smeltzer \n\nWynne - $330 Bn CDN in debt and climbing."
"@Don Pooley \n\nWorked for Justin."
"@Bertrum G.Gruff \n\nNothing in comparison to no less than 6 articles defending the disaster that was Justin's India visit."
"@Mark Johnson \n\nYou Liberals live in a fantasy world."
"@Pierre Dupuis \n\nIn the race to the bottom for indebtedness, Ontario defeats Quebec. It's another Wynne win!"
"@Billy Bayou \n\nHey, great job destroying diplomatic relations with India. Well done Liberals!"
"@Billy Bayou \n\nNo Billy, it's actually you that's denied the Liberal Party of a woman's leadership."
"@Billy Bayou \n\nThe Liberal Party of Canada has never voted to have a woman lead it."
"@Brent Grywinski \n\nLiberal voters believe Justin is part of the middle class."
"@Joe Brebeanu \n\nYOU.......Putin internet brigades."
"@Carl Street \n\nDon't be silly. Every good Liberal knows that high operating costs attract industry."
"@james Howard \n\nTrump channel turned off tonight?"
"@james Howard \n\nWynne did a great job chasing the Auto Industry out of Canada."
"@Carl Street \n\nI think Wynne's last 15 supporters are logged in tonight."
"@Dennis Regan \n\nWynne, out!"
"@Albert Johnson \n\nOntario Liberals should focus on trying to win the 2022 General Election."
"Wynne is a spent force. Bye bye Liberals!"
"@Mary Burns \n\nWynne is finished!"
"@Tony Belmore \n\nYup, Justin does. $1.2M CDN"
"@Skip Smith \n\nJustin has the most expensive car!"
"Yer done Wynne!"
"Great work Justin! Nobody is laughing at you."
"@Ed Logan \n\nLiberals want Omar Khadhr as their leader!"
"Justin is a dope!"
"@Dave Malottee \n\nSure, if that funding actually gets where it's needed. First nations in Canada are frank and honest. A quality that Liberals don't typically reward."
"@ian McDonald \n\nThe CBC is basically a parrot for the Liberal establishment while claiming that it's \"independent.\" That's what $2.5Bn CDN buys you!"
"Fresh borrowed cash for the elite Liberal class."
"What do you do when you can't raise enough campaign funds? Pass a budget into law that spreads billions of dollars into the hands of Liberal friendly \"non-profits.\""
"@Ben Dover \n\nLiberal \"activist.\""
"Lots of new spending, no vision and lots of that money going to Liberal friendly \"non-profits.\""
"A fresh lamb to sacrifice on the Liberal alter of Justin. Gerald Butts lives to tweet another day!"
"Thank you for embarassing Canada and making us a laughing stock. Thank you Justin, thank you Liberals!"
"@John Douglas \n\nMisogynistic commentary. The fourth quality of a Putin Brigade kid."
"@John Douglas \n\nFact\n\nJohn Douglas frequently changes identity. 5000 posts and the first time we've seen this \"handle.\" This is a Putin Brigade kid."
"@John Douglas \n\nYou're turbo posting is another quality of Putin's internet brigades."
"@John Douglas \n\nJohn Douglas.....Putin Brigades."
"@John Douglas \n\nWhy are you Putin Brigade people such chronic whiners?"
"@John Douglas \n\nYour poor command of the English language stands out like a sore thumb.\n\nJohn Douglas.....Putin Brigades."
"@John Douglas \n\nFact\n\nJohn Douglas lives in St. Petersburg"
EOT
exit 1
}
function x() {
printf "+ " >&2
# Protects words by escaping white space.
printf "%q " "${@}" >&2
# Puts single quotes around every word.
# printf "%s " "${@@Q}" >&2
printf "\n" >&2
local -i e=0
"$@" || e=$?
return ${e}
}
pos=0
user=""
prevcomment=""
search=""
limit=100
page=0
while (( $# )) ; do
case "$1" in
-a)
shift
prevcomment="$1"; shift || usage
;;
-l)
shift
limit="$1"; shift || usage
;;
-p)
shift
page=1
;;
*)
case ${pos} in
0)
user="$1"
;;
1)
search="$1"
;;
*)
usage
;;
esac
((pos+=1))
shift
;;
esac
done
if (( ! ${#user} )) ; then
usage
fi
if (( ${#prevcomment} )) ; then
api_filter_prevcomment="\"after_id\": ${prevcomment},"
else
api_filter_prevcomment=""
fi
if (( ${#search} )) ; then
jq_filter_search="| select (.content | test(\"(?i)${search}\"))"
jq_output="| .content"
else
jq_filter_search=""
jq_output=""
fi
set -e
if (( page && !${#jq_output} )) ; then
echo "["
fi
past_first_page=0
while : ; do
x curl -s --cacert ~/git-certs/zscaler-curl-bundle.pem -G "https://api.viafoura.co/v2/" \
--data-urlencode "json={
\"site\": \"www.cbc.ca\",
\"requests\": {\"comments\":{
\"limit\": ${limit},
${api_filter_prevcomment}
\"verb\": \"get\",
\"route\":\"/users/${user}/comments\"}}}" \
> /tmp/cbc-profile.json
x jq "[
.responses.comments.result.results[]
${jq_filter_search}
| {
id,
date_created: (.date_created | strftime(\"%Y-%m-%d %H:%M:%S\")),
content,
path: (\"https://cbc.ca\" + .page.path )
}
]" \
/tmp/cbc-profile.json \
> /tmp/cbc-profile-extract.json || {
echo "============ Error ==================" >&2
jq . /tmp/cbc-profile.json >&2 || cat /tmp/cbc-profile.json >&2
exit 1
}
if (( page )) ; then
last_id=$(jq ".responses.comments.result.results[-1].id" /tmp/cbc-profile.json)
if (( ${#jq_output} )) ; then
x jq ".[] ${jq_output}" /tmp/cbc-profile-extract.json
else
if [[ "${last_id}" != "null" ]] && (( past_first_page )) ; then
echo ","
fi
x jq "." /tmp/cbc-profile-extract.json | sed -e 1d -ne '$!p'
fi
past_first_page=1
if [[ "${last_id}" == "null" ]] ; then
break
else
api_filter_prevcomment="\"after_id\": ${last_id},"
fi
else
if (( ${#jq_output} )) ; then
x jq ".[] ${jq_output}" /tmp/cbc-profile-extract.json
else
x jq "." /tmp/cbc-profile-extract.json
fi
break
fi
done
if (( page && !${#jq_output} )) ; then
echo "]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment