@@ -31,21 +31,41 @@ def clean_tweet(orig_tweet):
31
31
cleanTweet = '' .join (str (x ) for x in cleanTweet )
32
32
return cleanTweet
33
33
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 ):
39
36
with open ("uncleanedtweets.txt" , "w" ) as unclean_file , open ("tweets.txt" , "w" ) as clean_file :
40
37
for tweet in results :
41
38
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
43
40
clean_text = clean_tweet (tweet .text )
44
41
clean_file .write (clean_text + '\n ' ) #create clean text file
45
42
46
43
#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
+
49
69
50
70
# # The search term you want to find
51
71
# query = "@realDonaldTrump"
0 commit comments