import re, math, collections, itertools
import nltk, nltk.classify.util, nltk.metrics
from nltk.classify import NaiveBayesClassifier
from nltk.metrics import BigramAssocMeasures
from nltk.probability import FreqDist, ConditionalFreqDist

from read_from_twitter import collated_twitter_data
from config import SEARCH_OLA_TERMS
from preprocess import preprocess_tweet
from filter_words import get_feature_list


tweet = collated_twitter_data(since='',until='',search_terms=SEARCH_OLA_TERMS)
preprocessed_tweets = preprocess_tweet(tweet)
filtered_tweet = get_feature_list(preprocessed_tweets)

print filtered_tweet

date_array = dict()
date_keys_others = [] #stores all dates data was present for other tweetting about us
date_keys_olacabs = [] #stors all the dates data was present for our tweeting

#for i in range(1,31):
#	date_array[str(i)+"_posititve"] = 0.0
#	date_array[str(i)+"_negative"] = 0.0
#	date_array[str(i)+"_count"] = 0
#	date_array[str(i)+"_count_of_olacabs"] = 0
#	date_array[i]["negative"] = 0.0

#csv priting
#print "Day of This Month ,Sentiment Positive Value, Sentiment Negative Value,Positive(True Or False)"
for page in range (1,5):
	tweets_from_others = collated_twitter_data(search_terms=["#olacabs","@olacabs","#ola cabs"],result_page=page,count_of_tweets=100)
	for tweet in tweets_from_others:
		result = sentiment(tweet["text"])
		date_of_data = tweet["timestamp"]
		#print tweet["timestamp"],",",result[0] , ",", result[1],",", positive(tweet["text"],0.1)
		date_array[str(date_of_data)+"_posititve"] = date_array.get(str(date_of_data)+"_posititve",0) + result[0]
		date_array[str(date_of_data)+"_negative"] = date_array.get(str(date_of_data)+"_negative",0) + result[1]
		date_array[str(date_of_data)+"_count"] = date_array.get(str(date_of_data)+"_count",0)+ 1
		date_keys_others.append(str(date_of_data))

for page in range (1,10):
	all_tweets_from_olacabs = get_all_olacabs_tweet(page,count=100)
	for tweet in all_tweets_from_olacabs:
		date_of_data = tweet["timestamp"]
		date_array[str(date_of_data)+"_count_of_olacabs"] = date_array.get((str(date_of_data)+"_count_of_olacabs"),0) + 1
		date_keys_olacabs.append(str(date_of_data))