Skip to content

Instantly share code, notes, and snippets.

@seigler
Last active June 18, 2017 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seigler/6ebb7033ca0c9c01e23aa64b255d8ce3 to your computer and use it in GitHub Desktop.
Save seigler/6ebb7033ca0c9c01e23aa64b255d8ce3 to your computer and use it in GitHub Desktop.
Hashtag photo collector
#!/bin/bash
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
json=$(mktemp)
hashtag="firstdashwallet"
regex="X[a-zA-Z0-9]{33}"
twurl "/1.1/search/tweets.json?q=%23$hashtag+filter:images&result_type=recent&count=100&tweet_mode=extended" > ${json}
while true; do
count=`cat ${json} | jq ".statuses | length"`
(( "$count" )) || break
echo "Found $count more tweets"
cat ${json} | jq -r ".statuses[] | (.full_text | match(\"$regex\").string) + \" \" + .entities.media[]?.media_url" >> addresses.txt
cat ${json} | jq -r ".statuses[] | if (.full_text | test(\"$regex\")) then .entities.media[]?.media_url else empty end" | wget -nc -q --show-progress -i -
nexturl=`cat ${json} | jq -r ".search_metadata.next_results"`
nexturl=`urldecode $nexturl`
twurl "/1.1/search/tweets.json$nexturl&tweet_mode=extended" > ${json}
done
rm ${json}
@seigler
Copy link
Author

seigler commented Jun 18, 2017

You will have to set up twurl and install jq first, but afterwards, this script will download all the photos matching a certain hashtag and a certain regular expression. It saves the photos with wget to the local folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment