kumistatus/twitools/__init__.py
2016-03-16 13:57:57 +01:00

50 lines
1 KiB
Python

import setuptools, tweepy
def cke():
try:
return setuptools.getSetting("Twitter", "cke")
except:
raise setuptools.SetupException()
def cse():
try:
return setuptools.getSetting("Twitter", "cse")
except:
raise setuptools.SetupException()
def ato():
try:
return setuptools.getSetting("Twitter", "ato")
except:
raise setuptools.SetupException()
def ase():
try:
return setuptools.getSetting("Twitter", "ase")
except:
raise setuptools.SetupException()
def user():
return twObject().whoami()
class twObject:
def __init__(self, cke = cke(), cse = cse(), ato = ato(), ase = ase()):
self.auth = tweepy.OAuthHandler(cke, cse)
self.auth.set_access_token(ato, ase)
self.api = tweepy.API(self.auth)
def delete(self, id):
self.api.destroy_status(id)
def search(self, query, savepoint = 0):
tweets = list(tweepy.Cursor(self.api.search, q=query, since_id=savepoint).items())
tweets.reverse()
return tweets
def tweet(self, text):
self.api.update_status(text)
def whoami(self):
return self.auth.get_username()