forked from prehensile/mundanebond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitterconnector.py
41 lines (32 loc) · 1.21 KB
/
twitterconnector.py
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
import tweepy
import os
class TwitterConnector( object ):
def __init__( self, creds_path ):
self.creds_path = creds_path
self._api = None
def api( self ):
if (self._api is None) and (self.creds_path is not None):
error = None
try:
fh = open( os.path.join( self.creds_path, 'consumer_token' ), 'r' )
consumer_key, consumer_secret = fh.read().split("\n")
fh.close()
except IOError, e:
error = e
try:
fh = open( os.path.join( self.creds_path, 'access_token' ), 'r' )
key, secret = fh.read().split("\n")
fh.close()
except IOError, e:
error = e
if error is None:
auth = tweepy.OAuthHandler( consumer_key, consumer_secret )
auth.set_access_token( key, secret )
self._api = tweepy.API( auth )
else:
logging.warning( error )
return self._api
def tweet( self, status ):
this_api = self.api()
if this_api is not None:
this_api.update_status( status )