-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet_Sentiment.py
60 lines (52 loc) · 2.96 KB
/
tweet_Sentiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3 -B
# tweet_Sentiment.py
# python3 -B tweet_Sentiment.py 'filecoin' 'Blue' 'Trump' 'Obama'
# Import necessary libraries
import codecs
import tweet_SearchAnalysis # Custom library to pull, store, analyse relevant tweets and returns the sentiment
import sys
search_words = sys.argv[1:]
this_list = ["Test"] #Test Standard
#this_list = ["Climate Change", "Global Warming", " SB32 "] #Standard
#this_list = ["Donald J Trump", "Texas", "Kansas", "Peach", "Plum", "Car", "Frown", "CNN", "FOX", "News", "Monday", "Mon", "Tuesday", "Tues", "Wednesday", "Wedn", "Thursday", "Thur", "Friday", "Fri", "Saturday", "Sat", "Sunday", "Sun", "Nude", "Scarf", "Archive", "AAPL", "BRK.A", "GOOG", "HPQ", "INTC", "MMM", "MSFT", "TGT", "WMT"]
# Stock tickers #A – Agilent Technologies #AAPL – Apple Inc. #BRK.A – Berkshire Hathaway (class A shares) #C – Citigroup #GOOG – Alphabet Inc. #HOG – Harley-Davidson Inc. #HPQ – Hewlett-Packard #INTC – Intel #KO – The Coca-Cola Company #LUV - Southwest Airlines (after their main hub at Love Field) #MMM – Minnesota Mining and Manufacturing (3M) #MSFT – Microsoft #T - AT&T #TGT – Target Corporation #TXN – Texas Instruments #WMT – Walmart
this_list = search_words
tweet_SearchAnalysis.twitter_API_rates()
def keyword_var_pac():
nameOfkeywords = []
keywordNameList = []
keywordKeyValue = {}
counter = 0
print(this_list)
for one_name in this_list:
keywordKeyValue[counter] = {}
keywordNameList.append(one_name)
keywordName = one_name
keywordKeyValue[counter]["keywordName"] = keywordName
counter += 1
#print(type(nameOfkeywords))
#print((nameOfkeywords))
#print(type(keywordKeyValue))
#print((keywordKeyValue))
return nameOfkeywords, keywordKeyValue
if __name__ == '__main__':
nameOfkeywords, keywordKeyValue = keyword_var_pac()
keyword = tweet_SearchAnalysis.tweet_SearchAnalysis()
# Final output will be stored at "Keyword_Sentiment_Results.txt"
outputFile = codecs.open("Keyword_Sentiment_Results.txt", 'w', "utf-8")
# Sentiment on of keywords
repeat_num = len(keywordKeyValue)
#print(keywordKeyValue)
for i in range(repeat_num):
keywordName = keywordKeyValue[i]["keywordName"]
keyword.tweetSearch(keywordName)
# Sentiment is calculated on keywords
keywordKeyValue[i]["tweet_Sentiment"] = keyword.tweetSentimentAnalysis(keywordName)
#print("Word searched for: " + keywordKeyValue[i]["keywordName"])
#print("Overall Sentiment on Twitter: " + keywordKeyValue[i]["tweet_Sentiment"] + "\n")
#print(keywordKeyValue[i])
outputFile.write("Word searched for: " + keywordKeyValue[i]["keywordName"] + "\n")
outputFile.write("Overall Sentiment on Twitter: " + str(keywordKeyValue[i]["tweet_Sentiment"]) + "\n")
outputFile.write("\n")
outputFile.close()
tweet_SearchAnalysis.twitter_API_rates()