-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwitterClass.py
More file actions
54 lines (41 loc) · 1.8 KB
/
TwitterClass.py
File metadata and controls
54 lines (41 loc) · 1.8 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
import tweepy
class TwitterClass:
'''Twitter class for use with twitter'''
def __init__(self, consumer_key, consumer_secret, access_token, access_token_secret):
self.consummer_key = consumer_key
self.consummer_secret = consumer_secret
self.access_token = access_token
self.access_toke_secret = access_token_secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
self.api = tweepy.API(auth)
def getTweets(self, url):
public_tweets = self.api.search([])
for tweet in public_tweets:
print(tweet.text)
def searchTweets(self, hashtag, limit):
cursor = tweepy.Cursor(self.api.search,
q=hashtag,
count=100,
result_type="recent").items(limit)
for tweet in cursor:
print(tweet.text)
def searchTweetsWithoutRT(self, hashtag, limit):
cursor = tweepy.Cursor(self.api.search,
q=hashtag + " -RT",
count=100,
result_type="recent").items(limit)
for tweet in cursor:
print(tweet.text)
def getLastTweetWithoutRT(self, hashtag):
cursor = tweepy.Cursor(self.api.search,
q=hashtag + " -RT",
count=100,
result_type="recent").items(1)
return cursor.next().text
def getTweetsWithoutRT(self, hashtag):
cursor = tweepy.Cursor(self.api.search,
q=hashtag + " -RT",
count=100,
result_type="recent").items(100)
return cursor