forked from ticketfrei/ticketfrei
merged
This commit is contained in:
commit
8ad4696179
|
@ -1,6 +1,8 @@
|
||||||
kontrolle
|
kontroll?e
|
||||||
konti
|
konti
|
||||||
db
|
db
|
||||||
|
vgn
|
||||||
|
vag
|
||||||
zivil
|
zivil
|
||||||
sicherheit
|
sicherheit
|
||||||
uniform
|
uniform
|
||||||
|
@ -11,12 +13,5 @@ tram
|
||||||
linie
|
linie
|
||||||
nuernberg
|
nuernberg
|
||||||
nürnberg
|
nürnberg
|
||||||
s1
|
s\d
|
||||||
s2
|
u\d\d?
|
||||||
s3
|
|
||||||
u1
|
|
||||||
u2
|
|
||||||
u3
|
|
||||||
s4
|
|
||||||
u21
|
|
||||||
u11
|
|
||||||
|
|
|
@ -191,10 +191,9 @@ if __name__ == "__main__":
|
||||||
trigger = trigger.Trigger(config)
|
trigger = trigger.Trigger(config)
|
||||||
|
|
||||||
bot = RetweetBot(trigger, config)
|
bot = RetweetBot(trigger, config)
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
bot.flow()
|
bot.flow()
|
||||||
try:
|
sleep(3)
|
||||||
pass
|
|
||||||
except:
|
except:
|
||||||
bot.shutdown()
|
bot.shutdown()
|
||||||
sleep(3)
|
|
||||||
|
|
|
@ -10,13 +10,17 @@ server = 'yourmastodoninstance'
|
||||||
consumer_key = "yourconsumerkey"
|
consumer_key = "yourconsumerkey"
|
||||||
consumer_secret = yourconsumersecret"
|
consumer_secret = yourconsumersecret"
|
||||||
|
|
||||||
|
# shutdown_contact_userid = 012345
|
||||||
|
# shutdown_contact_screen_name = 'yourscreenname'
|
||||||
|
|
||||||
[tuser]
|
[tuser]
|
||||||
access_token_key = "youraccesstokenkey"
|
access_token_key = "youraccesstokenkey"
|
||||||
access_token_secret = "youraccesstokensecret"
|
access_token_secret = "youraccesstokensecret"
|
||||||
|
|
||||||
# shutdown_contact_userid = 012345
|
|
||||||
# shutdown_contact_screen_name = 'yourscreenname'
|
|
||||||
|
|
||||||
# [trigger]
|
# [trigger]
|
||||||
|
# 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.
|
||||||
|
|
||||||
# goodlist_path = 'goodlists'
|
# goodlist_path = 'goodlists'
|
||||||
# blacklist_path = 'blacklists'
|
# blacklist_path = 'blacklists'
|
||||||
|
|
|
@ -20,7 +20,7 @@ if __name__ == '__main__':
|
||||||
statuses = []
|
statuses = []
|
||||||
while True:
|
while True:
|
||||||
statuses = mbot.retoot(statuses)
|
statuses = mbot.retoot(statuses)
|
||||||
statuses = tbot.flow(statuses) # XXX not implemented in RetweetBot
|
statuses = tbot.flow(statuses)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except:
|
except:
|
||||||
tbot.shutdown()
|
tbot.shutdown()
|
||||||
|
|
52
trigger.py
52
trigger.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
|
||||||
import pytoml as toml
|
import pytoml as toml
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class Trigger(object):
|
class Trigger(object):
|
||||||
|
@ -11,33 +12,32 @@ class Trigger(object):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.goodlistpath = config['trigger']['goodlist_path']
|
goodlistpath = config['trigger']['goodlist_path']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.goodlistpath = 'goodlists'
|
goodlistpath = 'goodlists'
|
||||||
self.goodlist = self.get_lists(self.goodlistpath)
|
|
||||||
|
# load goodlists
|
||||||
|
self.goodlist = []
|
||||||
|
for filename in os.listdir(goodlistpath):
|
||||||
|
with open(os.path.join(goodlistpath, filename), "r+") as listfile:
|
||||||
|
for pattern in listfile:
|
||||||
|
pattern = pattern.strip()
|
||||||
|
if pattern:
|
||||||
|
self.goodlist.append(re.compile(pattern))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.blacklistpath = config['trigger']['blacklist_path']
|
blacklistpath = config['trigger']['blacklist_path']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.blacklistpath = 'blacklists'
|
blacklistpath = 'blacklists'
|
||||||
self.blacklist = self.get_lists(self.blacklistpath)
|
|
||||||
|
|
||||||
def get_lists(self, path):
|
# load blacklists
|
||||||
"""
|
self.blacklist = set()
|
||||||
pass a folder with text files in it. each line in the files becomes a
|
for filename in os.listdir(blacklistpath):
|
||||||
filter word.
|
with open(os.path.join(blacklistpath, filename), "r+") as listfile:
|
||||||
|
|
||||||
:param path: path to folder whose files shall be added to the set
|
|
||||||
:return: set of trigger words.
|
|
||||||
"""
|
|
||||||
trigger_words = set()
|
|
||||||
for filename in os.listdir(path):
|
|
||||||
with open(os.path.join(path, filename), "r+") as listfile:
|
|
||||||
for word in listfile:
|
for word in listfile:
|
||||||
word = word.strip()
|
word = word.strip()
|
||||||
if word:
|
if word:
|
||||||
trigger_words.add(word)
|
self.blacklist.add(word)
|
||||||
return trigger_words
|
|
||||||
|
|
||||||
def is_ok(self, message):
|
def is_ok(self, message):
|
||||||
"""
|
"""
|
||||||
|
@ -46,13 +46,17 @@ class Trigger(object):
|
||||||
:param message: A given string. Tweet or Toot, cleaned from html.
|
:param message: A given string. Tweet or Toot, cleaned from html.
|
||||||
:return: If the string passes the test
|
:return: If the string passes the test
|
||||||
"""
|
"""
|
||||||
ret = False
|
for pattern in self.goodlist:
|
||||||
|
if pattern.match(message):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# no pattern matched
|
||||||
|
return False
|
||||||
|
|
||||||
for word in message.lower().split():
|
for word in message.lower().split():
|
||||||
if word in self.goodlist:
|
|
||||||
ret = True
|
|
||||||
if word in self.blacklist:
|
if word in self.blacklist:
|
||||||
return False
|
return False
|
||||||
return ret
|
return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue