That's the tweeter

This commit is contained in:
Klaus-Uwe Mitterer 2016-03-16 13:44:50 +01:00
commit 659096aace
2 changed files with 67 additions and 0 deletions

8
tweet.py Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env python3
import twitools
if __name__ == "__main__":
two = twitools.twObject()
text = input("> ")
two.tweet(text)

59
twitools.py Normal file
View file

@ -0,0 +1,59 @@
import configparser, tweepy
class SetupException(Exception):
def __str__(self):
return "Seems like config.cfg has not been created yet. Run setup.py to do so."
def getSetting(section, setting):
config = configparser.RawConfigParser()
config.read('config.cfg')
return config.get(section, setting)
def cke():
try:
return getSetting("Twitter", "cke")
except:
raise SetupException()
def cse():
try:
return getSetting("Twitter", "cse")
except:
raise SetupException()
def ato():
try:
return getSetting("Twitter", "ato")
except:
raise SetupException()
def ase():
try:
return getSetting("Twitter", "ase")
except:
raise 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()