Last active
August 29, 2015 13:56
-
-
Save sufw/8952129 to your computer and use it in GitHub Desktop.
traceTweetLinks.sh
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/bash | |
# Recursively follows the first link in a tweet until it reaches the bottom 'root' tweet. | |
# Built without any testing to trace the origin of this meme: https://twitter.com/sufw/status/433495556300603393 | |
# Published at https://gist.github.com/sufw/8952129 | |
i=0; | |
startingTweet=$1; | |
if [ "$#" -ne 1 ] | |
then | |
echo "Usage: " 1>&2; | |
echo " Please call this script with the URL of a tweet as an argument" 1>&2; | |
echo " e.g. $0 https://twitter.com/sufw/status/433495556300603393" 1>&2; | |
echo " " 1>&2; | |
exit 1; | |
fi | |
while [ $i -lt 1024 ]; do | |
nextTweet=$(curl $startingTweet 2>/dev/null | grep -o -e 'class="js-tweet-text tweet-text".*' | head -1 | grep -o -e 'data-expanded-url="[^"]*"' | head -1 | sed 's/data-expanded-url=//' | sed 's/"//g'); | |
if [[ "$nextTweet" != "$startingTweet" ]]; then | |
echo "$i: $startingTweet --> $nextTweet"; | |
startingTweet="$nextTweet"; | |
let i=i+1; | |
else | |
break; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment