-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentimentmonitor.py
More file actions
114 lines (67 loc) · 3.02 KB
/
Copy pathsentimentmonitor.py
File metadata and controls
114 lines (67 loc) · 3.02 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import tweepy, json, re;
from tweepy import OAuthHandler;
########################
# Function Definitions #
########################
def GetFollowers( oUserId ) :
listFollowers = oApi.followers( user_id = oUserId )
print( "Number of Followers: ", str( len( listFollowers ) ) );
def SearchTweet( strTweet, strSearchTerm ) :
boolTermFound = re.search( strSearchTerm, strTweet )
if boolTermFound :
return True
else :
return False;
def GetTweets( oUserId, strTerm = "" ) :
print( "*****************************" )
print( "tweets for: ", str( oUserId ) )
print( "*****************************" )
listTweets = oApi.user_timeline( user_id = oUserId, count = 10 );
# print( "Number of tweets: ", len( listTweets ) );
for tweet in listTweets :
# print( json.dumps( tweet._json, indent = 4 ) );
objTweet = json.dumps( tweet._json, sort_keys = True, indent = 4 )
try :
# json.loads() loads a string parameter, while json.load takes a file parameter
jsonTweet = json.loads( objTweet )
print( "Name:", jsonTweet["user"]["name"] )
print( "Screen Name:", jsonTweet["user"]["screen_name"] )
print( "Posted at:", str( jsonTweet["created_at"] ) )
print( "Number of Favorites:", str( jsonTweet["favorite_count"] ) )
print( "Number of Retweets:", str( jsonTweet["retweet_count"] ) )
print( "*************************************" );
strTweetText = str( jsonTweet["text"] )
if len( strTerm ) > 0 :
boolFound = SearchTweet( strTweetText, strTerm )
if boolFound :
print( strTweetText, "contains search term: ", strTerm )
else :
print( strTweetText, "does not contain search term: ", strTerm );
else :
print( "Tweet:", strTweetText );
except :
print( "Can't pull text" );
print( "*************************************" )
# print( strTweet );
########################################################################
########################################################################
################
# Main Runtime #
################
strCKey = "";
strCSecret = "";
strAToken = "";
strASecret = "";
strInputTerm = input( "Please enter a search term, otherwise press enter: " )
print( "Len of Term:", str( len( strInputTerm ) ) )
oAuth = OAuthHandler( strCKey, strCSecret );
oAuth.set_access_token( strAToken, strASecret );
oApi = tweepy.API( oAuth );
listFriends = oApi.friends_ids();
print( listFriends );
for oFriendId in range( len( listFriends ) ) :
print( "FriendId:", str( listFriends[ oFriendId ] ) )
iFriendId = int( listFriends[ oFriendId ] )
GetTweets( iFriendId, strInputTerm );
# pushes over rate limit
# GetFollowers( iFriendId );