Last active
January 28, 2018 06:03
-
-
Save ryanwoodsmall/48d9bbc9d4e642081d372a11b6b37cde to your computer and use it in GitHub Desktop.
dump twitter block list to paged json files with cursors / block twitter advertisers / etc.
This file contains hidden or 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/bash | |
mkdir -p out | |
for i in $(cat advertisers_to_block.txt) ; do | |
{ | |
echo '{ "'${i}'" : [' | |
twurl -d "screen_name=${i}" /1.1/blocks/create.json | jq -M . | |
echo ' ] }' | |
} | tee out/${i}.json >/dev/null 2>&1 | |
echo ${i} | |
sleep 1 | |
done |
This file contains hidden or 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/bash | |
page="0" | |
next_cursor="-1" | |
while [ ${next_cursor} -ne 0 ] ; do | |
twurl "/1.1/blocks/ids.json?cursor=${next_cursor}" | jq . > page${page}.json | |
echo page${page}.json | |
next_cursor="$(jq .next_cursor page${page}.json)" | |
echo ${next_cursor} | |
((page++)) | |
sleep 1 | |
done |
This file contains hidden or 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/bash | |
# dump twitter user ids from above with: | |
# jq .ids[] page*.json > idfile.out | |
# run this against it to create batches of 100 comma-separated ids | |
if [ ! ${#} -eq 1 ] ; then | |
echo "please provide a file to chunk" | |
exit | |
fi | |
lc="$(wc -l ${1} | awk '{print $1}')" | |
head=100 | |
inc=100 | |
while [ ${head} -lt ${lc} ] ; do | |
tail="${inc}" | |
if [ ! $((${lc}-${head})) -ge ${inc} ] ; then | |
tail="$((${lc}-${head}))" | |
fi | |
head -${head} ${1} | tail -${tail} | xargs echo | tr ' ' ',' | |
head="$((${head}+${inc}))" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment