This commit is contained in:
b3yond 2017-07-27 16:59:08 +02:00
commit 820dfcd504
4 changed files with 27 additions and 8 deletions

View file

@ -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. 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 ## 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 * 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

View file

@ -42,10 +42,14 @@ class RetootBot(object):
message = message + " The traceback is located at " + os.path.join("logs" + time) message = message + " The traceback is located at " + os.path.join("logs" + time)
with open(os.path.join("logs", time), 'w+') as f: with open(os.path.join("logs", time), 'w+') as f:
f.write(tb) f.write(tb)
line = "[" + time + "] "+ message line = "[" + time + "] "+ message + "\n"
with open(self.logpath, 'a') as f: with open(self.logpath, 'a') as f:
f.write(line) try:
print line 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): def register(self):
self.client_id = os.path.join( self.client_id = os.path.join(

View file

@ -29,6 +29,7 @@ class RetweetBot(object):
:param historypath: Path to the file with ID of the last retweeted :param historypath: Path to the file with ID of the last retweeted
Tweet Tweet
:param logpath: Path to the file where the log is stored
""" """
self.config = config self.config = config
keys = self.get_api_keys() keys = self.get_api_keys()
@ -38,6 +39,7 @@ class RetweetBot(object):
access_token_secret=keys[3]) access_token_secret=keys[3])
self.historypath = historypath self.historypath = historypath
try: try:
self.no_shutdown_contact = False
self.user_id = self.config['tapp']['shutdown_contact_userid'] self.user_id = self.config['tapp']['shutdown_contact_userid']
self.screen_name = \ self.screen_name = \
self.config['tapp']['shutdown_contact_screen_name'] self.config['tapp']['shutdown_contact_screen_name']
@ -48,7 +50,7 @@ class RetweetBot(object):
if logpath: if logpath:
self.logpath = logpath self.logpath = logpath
else: 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 print "Path of logfile: " + self.logpath
def get_api_keys(self): def get_api_keys(self):
@ -85,10 +87,14 @@ class RetweetBot(object):
message = message + " The traceback is located at " + os.path.join("logs" + time) message = message + " The traceback is located at " + os.path.join("logs" + time)
with open(os.path.join("logs", time), 'w+') as f: with open(os.path.join("logs", time), 'w+') as f:
f.write(tb) f.write(tb)
line = "[" + time + "] "+ message line = "[" + time + "] "+ message + "\n"
with open(self.logpath, 'a') as f: with open(self.logpath, 'a') as f:
f.write(line) try:
print line 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): def get_history(self, path):
""" This counter is needed to keep track of your mentions, so you """ This counter is needed to keep track of your mentions, so you
@ -136,7 +142,7 @@ class RetweetBot(object):
return mentions return mentions
except twitter.TwitterError: except twitter.TwitterError:
self.log("Twitter API Error: Rate Limit Exceeded.") self.log("Twitter API Error: Rate Limit Exceeded.")
sleep(60) sleep(120)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
self.log("Twitter API Error: Bad Connection.") self.log("Twitter API Error: Bad Connection.")
sleep(10) sleep(10)

View file

@ -21,6 +21,7 @@ access_token_secret = "youraccesstokensecret"
# goodlists are one regex per line. # goodlists are one regex per line.
# badlists are one badword per line. # badlists are one badword per line.
# a message musst match at least one regex in goodlist and contain none of the badwords. # 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' # goodlist_path = 'goodlists'
# blacklist_path = 'blacklists' # blacklist_path = 'blacklists'