diff --git a/badlist b/blacklist similarity index 100% rename from badlist rename to blacklist diff --git a/retweetbot.py b/retweetbot.py index f0e7ddc..0463d62 100644 --- a/retweetbot.py +++ b/retweetbot.py @@ -1,11 +1,13 @@ #!/usr/bin/env python -__encoding__ = "utf-8" import twitter import requests +import pytoml as toml import trigger from time import sleep +__encoding__ = "utf-8" + class RetweetBot(object): """ @@ -18,7 +20,7 @@ class RetweetBot(object): last_mention: the ID of the last tweet which mentioned you """ - def __init__(self, trigger=trigger.Trigger(), + def __init__(self, trigger, keypath="appkeys/ticketfrei@twitter.com", historypath="last_mention", triggerpath="goodlist", @@ -182,9 +184,15 @@ class RetweetBot(object): if __name__ == "__main__": # create an Api object - bot = RetweetBot() + with open('ticketfrei.cfg') as configfile: + config = toml.load(configfile) + + trigger = trigger.Trigger(config) + + bot = RetweetBot(trigger=trigger) while True: - bot.flow() - sleep(10) - #except: - # bot.shutdown() + try: + bot.flow() + except: + bot.shutdown() + sleep(1) diff --git a/ticketfrei.cfg.example b/ticketfrei.cfg.example index 0fa4f05..f77e6b2 100644 --- a/ticketfrei.cfg.example +++ b/ticketfrei.cfg.example @@ -22,4 +22,13 @@ consumer_secret = "09muvs098u08m9vsum098mu" access_token_key = "u098umgfres09ug-f7n60cwhxm12" access_token_secret = "8708mj9ßc298m343333333tex" +[goodlist] +asdf +oigna +bahn +zu spät + +[blacklist] +insult +slur diff --git a/ticketfrei.py b/ticketfrei.py index cbdab0a..e6109c8 100644 --- a/ticketfrei.py +++ b/ticketfrei.py @@ -11,7 +11,7 @@ if __name__ == '__main__': with open('ticketfrei.cfg') as configfile: config = toml.load(configfile) - trigger = Trigger() + trigger = Trigger(config) mbot = RetootBot(config) tbot = RetweetBot(config, trigger=trigger) diff --git a/trigger.py b/trigger.py index 0109ca5..3a4fe2b 100644 --- a/trigger.py +++ b/trigger.py @@ -6,21 +6,27 @@ class Trigger(object): """ This class provides a filter to test a string against. """ - def __init__(self, goodlistpath="goodlist", badlistpath="badlist"): + def __init__(self, config, goodlistpath="goodlist", blacklistpath="blacklist"): + self.config = config + self.goodlistpath = goodlistpath with open(goodlistpath, "r+") as f: self.goodlist = [s.strip() for s in f.readlines()] + for word in config["goodlist"]: + self.goodlist.append(word) self.goodlist = self.strings_ok(self.goodlist) - self.badlistpath = badlistpath - with open(badlistpath, "r+") as f: - self.badlist = [s.strip() for s in f.readlines()] - self.badlist = self.strings_ok(self.badlist) + self.blacklistpath = blacklistpath + with open(blacklistpath, "r+") as f: + self.blacklist = [s.strip() for s in f.readlines()] + for word in config["blacklist"]: + self.blacklist.append(word) + self.blacklist = self.strings_ok(self.blacklist) def strings_ok(self, filterlist): """ Checks if an empty line is in a list and removes it. - :param filterlist: a good- or badlist. + :param filterlist: a good- or blacklist. :return: filterlist: a corrected list. """ for word in filterlist: @@ -38,7 +44,7 @@ class Trigger(object): string = unicode.decode(string) for triggerword in self.goodlist: if string.lower().find(triggerword) != -1: - for triggerword in self.badlist: + for triggerword in self.blacklist: if string.lower().find(triggerword) != -1: return False return True @@ -53,7 +59,7 @@ class Trigger(object): if whichlist: path = self.goodlistpath else: - path = self.badlistpath + path = self.blacklistpath with open(path, "w") as f: old = f.readlines() old.append(word) diff --git a/trigger.pyc b/trigger.pyc index 301bc27..192aab0 100644 Binary files a/trigger.pyc and b/trigger.pyc differ