Created
August 5, 2016 15:19
-
-
Save hernamesbarbara/c2b56fe8177e1bac009ba5c114d33c72 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
#!/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