diff --git a/README.md b/README.md index 0605a7f..83b1f98 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,14 @@ There is also a blacklist, which you can use to automatically sort out malicious Note that atm the good- & blacklist are still outside of ticketfrei.cfg, in separate files. we will repare this soon. +To keep the bots running when you are logged out of the shell, you can use screen: + +```shell +sudo apt-get install screen +screen +python ticketfrei.py +``` + ## ideas * You can only use the twitter API if you have confirmed a phone number and sacrificed a penguin in a blood ritual. So we should build it in a way that it uses the twitter web GUI. It's difficult, but maybe it works. We had another twitter bot that worked similarly, years ago: https://github.com/b3yond/twitter-bot diff --git a/retootbot.py b/retootbot.py index d7eea99..46032ab 100644 --- a/retootbot.py +++ b/retootbot.py @@ -42,10 +42,14 @@ class RetootBot(object): message = message + " The traceback is located at " + os.path.join("logs" + time) with open(os.path.join("logs", time), 'w+') as f: f.write(tb) - line = "[" + time + "] "+ message + line = "[" + time + "] "+ message + "\n" with open(self.logpath, 'a') as f: - f.write(line) - print line + try: + f.write(line) + except UnicodeEncodeError: + self.log("Failed to save log message due to UTF-8 error. ") + traceback.print_exc() + print line, def register(self): self.client_id = os.path.join( diff --git a/retweetbot.py b/retweetbot.py index fbae911..aab66c7 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -29,6 +29,7 @@ class RetweetBot(object): :param historypath: Path to the file with ID of the last retweeted Tweet + :param logpath: Path to the file where the log is stored """ self.config = config keys = self.get_api_keys() @@ -38,6 +39,7 @@ class RetweetBot(object): access_token_secret=keys[3]) self.historypath = historypath try: + self.no_shutdown_contact = False self.user_id = self.config['tapp']['shutdown_contact_userid'] self.screen_name = \ self.config['tapp']['shutdown_contact_screen_name'] @@ -48,7 +50,7 @@ class RetweetBot(object): if logpath: self.logpath = logpath else: - self.logpath = os.path.join("logs", "{%Y-%m-%d_%H:%M:%S}".format(datetime.datetime.now())) + self.logpath = os.path.join("logs", str(datetime.datetime.now())) print "Path of logfile: " + self.logpath def get_api_keys(self): @@ -85,10 +87,14 @@ class RetweetBot(object): message = message + " The traceback is located at " + os.path.join("logs" + time) with open(os.path.join("logs", time), 'w+') as f: f.write(tb) - line = "[" + time + "] "+ message + line = "[" + time + "] "+ message + "\n" with open(self.logpath, 'a') as f: - f.write(line) - print line + try: + f.write(line) + except UnicodeEncodeError: + self.log("Failed to save log message due to UTF-8 error. ") + traceback.print_exc() + print line, def get_history(self, path): """ This counter is needed to keep track of your mentions, so you @@ -136,7 +142,7 @@ class RetweetBot(object): return mentions except twitter.TwitterError: self.log("Twitter API Error: Rate Limit Exceeded.") - sleep(60) + sleep(120) except requests.exceptions.ConnectionError: self.log("Twitter API Error: Bad Connection.") sleep(10) diff --git a/ticketfrei.cfg.example b/ticketfrei.cfg.example index d6d3d2f..39d9cf6 100644 --- a/ticketfrei.cfg.example +++ b/ticketfrei.cfg.example @@ -21,6 +21,7 @@ access_token_secret = "youraccesstokensecret" # goodlists are one regex per line. # badlists are one badword per line. # a message musst match at least one regex in goodlist and contain none of the badwords. +# the variables mention the directory where the lists are located, not the filenames. # goodlist_path = 'goodlists' # blacklist_path = 'blacklists'