Exemple #1
0
def saveCounts():
    with open('total-counts.csv', 'w') as counts:
            counts= csv.DictWriter(counts, states.keys())
            counts.writeheader()
            counts.writerow(states)
    
if __name__ == '__main__':

    #geolocator = GoogleV3()

    tweets = open('test.json', 'w', encoding='utf-8')
    tweets.close()
    
    sentiment_file_writer =  csv.writer(open('FFsentiment.csv','w'), lineterminator='\n')
    
    sentimentClassifier = NaiveBayes.getSentimentClassifier()
    print("Sentiment Classifier Created")
    
    sentimentTokenizer = happytokenizer.TweetTokenizer()

    #This handles Twitter authentication and the connection to Twitter Streaming API
    Tweetlistener = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, Tweetlistener)

    #This line filter Twitter Streams to capture data posted from US in English with utf-8 encoding
    while True:
        try:
            stream.filter(languages=['en'], async=False, locations=[-125,25,-65,48])
        except: