-
-
Save flaviosilveira/d67e4f4eeeb640b8448ee05ebdd31cb2 to your computer and use it in GitHub Desktop.
Gather Geo-Tagged Tweets using Twitter Streaming API | Just change the line 31 to catch tweets from where you want
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 | |
#Function to Encode | |
# Thanks to https://gist.github.com/cdown/1163649/8a35c36fdd24b373788a7057ed483a5bcd8cd43e | |
encode() { | |
local _length="${#1}" | |
for (( _offset = 0 ; _offset < _length ; _offset++ )); do | |
_print_offset="${1:_offset:1}" | |
case "${_print_offset}" in | |
[a-zA-Z0-9.~_-]) printf "${_print_offset}" ;; | |
' ') printf + ;; | |
*) printf '%%%X' "'${_print_offset}" ;; | |
esac | |
done | |
} | |
./twitter-config.sh | |
# Consumer Key | |
key=$consumer_key | |
# Consumer Secret | |
secret=$consumer_secret | |
# Access Token | |
token=$access_token | |
# Access Token Secret | |
token_secret=$access_secret | |
method='POST' | |
url='https://stream.twitter.com/1.1/statuses/filter.json' | |
# San Francisco | |
data='locations=-122.75%2C36.8%2C-121.75%2C37.8' | |
# Big Curitiba Area | |
#data='locations=-49.591599%2C-25.646478%2C-48.961945%2C-25.281954' | |
#encoded for Signature | |
encoded_url=$(encode $url) | |
encoded_data=$(encode $data) | |
nonce=`date +%s%T%N | openssl base64 | sed -e s'/[+=/]//g' | head -c 32` | |
timestamp=`date +%s` | |
signature=`echo -n $method'&'$encoded_url'&'$encoded_data'%26oauth_consumer_key%3D'$key'%26oauth_nonce%3D'$nonce'%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D'$timestamp'%26oauth_token%3D'$token'%26oauth_version%3D1.0' | openssl dgst -sha1 -hmac $secret'&'$token_secret -binary | openssl base64 | sed -e s'/+/%2B/' -e s'/\//%2F/' -e s'/=/%3D/'` | |
curl $url --data $data --header 'Authorization: OAuth oauth_consumer_key="'$key'", oauth_nonce="'$nonce'", oauth_signature="'$signature'", oauth_signature_method="HMAC-SHA1", oauth_timestamp="'$timestamp'", oauth_token="'$token'", oauth_version="1.0"' --verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment