import tweepy, csv, time
import pandas as pd

#"""
consumer_key = 'GSDyidvmJDvBMlGsbwXd5oJcr'
consumer_secret = '<KEY>'
access_token = '<KEY>'
access_token_secret = '<KEY>'
#"""
'''
consumer_key = 'vU17b7Kb18pZlgjx9Oc43aWEj'
consumer_secret = '<KEY>'
access_token = '<KEY>'
access_token_secret = '<KEY>'
'''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)

tweets = []
query = "hate"

print("starting crawl:",query)

try:
    for tweet in tweepy.Cursor(api.search,q="#"+query,lang="en",since="2017-01-01").items(2000):
        text = tweet.text.replace("&amp;","&").replace(",","").replace("RT","")
        print(text)
        tweets.append(text)
        time.sleep(1e-3)
    pd.DataFrame(tweets).to_csv(query+".csv")
except Exception as e:
    print(e)
    pd.DataFrame(tweets).to_csv(query+".csv")

import tweepy, csv, time
import pandas as pd

#"""
consumer_key = 'GSDyidvmJDvBMlGsbwXd5oJcr'
consumer_secret = '<KEY>'
access_token = '<KEY>'
access_token_secret = '<KEY>'
#"""
'''
consumer_key = 'vU17b7Kb18pZlgjx9Oc43aWEj'
consumer_secret = '<KEY>'
access_token = '<KEY>'
access_token_secret = '<KEY>'
'''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)

tweets = []
query = "hate"

print("starting crawl:",query)

try:
    for tweet in tweepy.Cursor(api.search,q="#"+query,lang="en",since="2017-01-01").items(2000):
        text = tweet.text.replace("&amp;","&").replace(",","").replace("RT","")
        print(text)
        tweets.append(text)
        time.sleep(1e-3)
    pd.DataFrame(tweets).to_csv(query+".csv")
except Exception as e:
    print(e)
    pd.DataFrame(tweets).to_csv(query+".csv")

#""" #""" consumer_key = 'vU17b7Kb18pZlgjx9Oc43aWEj' consumer_secret = '<KEY>' access_token = '<KEY>' access_token_secret = '<KEY>'