-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweeter.py
More file actions
33 lines (25 loc) · 954 Bytes
/
Tweeter.py
File metadata and controls
33 lines (25 loc) · 954 Bytes
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
import tweepy
from tweepy import TweepError
from config import *
from TweetResult import TweetResult
class Tweeter:
'Class for retrieving results from timeline, and sending messages'
__latestId = 1
def __init__(self):
auth = tweepy.OAuthHandler(TW_CONSUMER_KEY, TW_CONSUMER_SECRET)
auth.set_access_token(TW_ACCESS_TOKEN, TW_ACCESS_SECRET)
self.__api = tweepy.API(auth)
def getResults(self):
results = []
for r in self.__api.mentions_timeline(self.__latestId):
if (r.id > self.__latestId):
self.__latestId = r.id
if(len(r.entities['hashtags']) > 0):
t = TweetResult(r.id, r.author.screen_name, r.entities['hashtags'])
results.append(t)
return results
def sendTweet(self, msg, id):
try:
self.__api.update_status(msg, id)
except TweepError as e:
print(e.response.text)