Skip to content

Commit 0711894

Browse files
committed
working on basic sentiment analysis
1 parent bfe8c8d commit 0711894

File tree

3 files changed

+2034
-8
lines changed

3 files changed

+2034
-8
lines changed

app.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,41 @@ def clean_tweet(orig_tweet):
3131
cleanTweet = ''.join(str(x) for x in cleanTweet)
3232
return cleanTweet
3333

34-
35-
def main():
36-
37-
results = tweepy.Cursor(api.user_timeline, screen_name=sys.argv[1]).items(number_tweets_to_get)
38-
34+
#grabs and puts clean and uncleaned tweets in files
35+
def grabTweets(results):
3936
with open("uncleanedtweets.txt", "w") as unclean_file, open("tweets.txt", "w") as clean_file:
4037
for tweet in results:
4138
tweet.text = tweet.text.encode('utf-8') #encode the string properly
42-
unclean_file.write(tweet.text + '\n') #create unclean text file
39+
unclean_file.write('tweet: ' + tweet.text + '\n') #create unclean text file
4340
clean_text = clean_tweet(tweet.text)
4441
clean_file.write(clean_text + '\n') #create clean text file
4542

4643
#Exclude all retweets
47-
if (not tweet.retweeted) and ('RT @' not in tweet.text):
48-
print(clean_text)
44+
# if (not tweet.retweeted) and ('RT @' not in tweet.text):
45+
# print(clean_text)
46+
47+
#count positive words in a single cleaned tweet
48+
def countPositiveWords():
49+
#split all tweets into a list of words
50+
lines = open('tweets.txt', 'rb').readlines()
51+
positiveWords = set(line.strip() for line in open('positiveW.txt'))
52+
53+
#find matches of positive words in the tweet
54+
for line in lines:
55+
words = line.split()
56+
count = 0
57+
for word in words:
58+
if word in positiveWords:
59+
count+=1
60+
print count
61+
62+
63+
64+
def main():
65+
results = tweepy.Cursor(api.user_timeline, screen_name=sys.argv[1]).items(number_tweets_to_get)
66+
grabTweets(results);
67+
countPositiveWords()
68+
4969

5070
# # The search term you want to find
5171
# query = "@realDonaldTrump"

negativeW.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)