<filename>Proyecto2BIM/get_tweets.py
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener

#  API CREDENTIALS

ckey = "XTwJNYD8b9bekoIvJ4q5j1JUf"
csecret = "<KEY>"
atoken = "<KEY>"
asecret = "<KEY>"


class listener(StreamListener):

    def on_data(self, data):
        with open('tweets_mexico.json', 'a') as diccionario:
            diccionario.write(data+",")
        return True

    def on_error(self, status):
        print (status)


auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())


filters = [
    'donaldtrump',
    'trump',
    'goverment',
    'whitehouse',
    'Trump'
]


# EEUU = -120.3,29.7,-87.8,46.3
# RUS = 37.28,52.72,91.07,66.19
# JAPON 131.46,30.57,146.57,44.94
# MEXICO -113.13,11.19,-88.91,31.74

twitterStream.filter(locations=[-113.13,11.19,-88.91,31.74], track=filters)
<filename>Proyecto2BIM/get_tweets.py
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener

#  API CREDENTIALS

ckey = "XTwJNYD8b9bekoIvJ4q5j1JUf"
csecret = "<KEY>"
atoken = "<KEY>"
asecret = "<KEY>"


class listener(StreamListener):

    def on_data(self, data):
        with open('tweets_mexico.json', 'a') as diccionario:
            diccionario.write(data+",")
        return True

    def on_error(self, status):
        print (status)


auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())


filters = [
    'donaldtrump',
    'trump',
    'goverment',
    'whitehouse',
    'Trump'
]


# EEUU = -120.3,29.7,-87.8,46.3
# RUS = 37.28,52.72,91.07,66.19
# JAPON 131.46,30.57,146.57,44.94
# MEXICO -113.13,11.19,-88.91,31.74

twitterStream.filter(locations=[-113.13,11.19,-88.91,31.74], track=filters)
#  API CREDENTIALS # EEUU = -120.3,29.7,-87.8,46.3 # RUS = 37.28,52.72,91.07,66.19 # JAPON 131.46,30.57,146.57,44.94 # MEXICO -113.13,11.19,-88.91,31.74