Skip to content

Instantly share code, notes, and snippets.

@hernamesbarbara
Created August 5, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hernamesbarbara/c2b56fe8177e1bac009ba5c114d33c72 to your computer and use it in GitHub Desktop.
Save hernamesbarbara/c2b56fe8177e1bac009ba5c114d33c72 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# use t CLI to fetch follower count and other stats from twitter
# save results to a csv file
if [ -z "$1" ]; then
echo "no username specified" >&2
exit 1
else
SCREEN_NAME="$1"
OUTFILE="twitter-whois-"$SCREEN_NAME".csv"
fi
if [ ! -f $OUTFILE ]; then
echo "Creating an output csv file to save data..."
touch "$OUTFILE"
fi
echo ""$OUTFILE" has $(wc -l<"$OUTFILE") rows"
echo "fetching data from twitter..."
if [[ $(wc -l <"$OUTFILE") -ge 2 ]]; then
t whois $SCREEN_NAME --csv --long | tail -n +2 >> $OUTFILE
else
t whois $SCREEN_NAME --csv --long >> $OUTFILE
fi
# remove duplicates and overwrite the file
awk '!seen[$0]++' $OUTFILE > tmp.csv
# if all worked then overwrite contents of original file
if [[ $(wc -l <tmp.csv) -ge 2 ]]; then
mv tmp.csv $OUTFILE -f
echo "Results written to $OUTFILE"
echo ""$OUTFILE" has $(wc -l<"$OUTFILE") rows"
echo "done"
exit 0
else
echo "something went wrong"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment