implemented mastodon DMs, city, and backend.shutdown function
This commit is contained in:
parent
9b01ac7eac
commit
758ff1db46
|
@ -139,6 +139,9 @@ There are several logfiles which you can look at:
|
|||
# for the uwsgi deployment:
|
||||
less /var/log/ticketfrei/uwsgi.log
|
||||
|
||||
# for the backend:
|
||||
less /var/log/ticketfrei/backend.log
|
||||
|
||||
# for the systemd service:
|
||||
less /var/log/syslog
|
||||
|
||||
|
|
|
@ -34,16 +34,29 @@ class MastodonBot(Bot):
|
|||
text = re.sub(
|
||||
"(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
||||
"", text)
|
||||
mentions.append(Report(status['account']['acct'],
|
||||
self,
|
||||
text,
|
||||
status['status']['id'],
|
||||
status['status']['created_at']))
|
||||
if status['status']['visibility'] == 'public':
|
||||
mentions.append(Report(status['account']['acct'],
|
||||
self,
|
||||
text,
|
||||
status['status']['id'],
|
||||
status['status']['created_at']))
|
||||
else:
|
||||
mentions.append(Report(status['account']['acct'],
|
||||
'mastodonPrivate',
|
||||
text,
|
||||
status['status']['id'],
|
||||
status['status']['created_at']))
|
||||
return mentions
|
||||
|
||||
def post(self, user, report):
|
||||
m = Mastodon(*user.get_masto_credentials())
|
||||
if report.source == self:
|
||||
m.status_reblog(report.id)
|
||||
try:
|
||||
m.status_reblog(report.id)
|
||||
except Exception:
|
||||
logger.error('Error boosting: ' + report.id, exc_info=True)
|
||||
else:
|
||||
m.toot(report.text)
|
||||
try:
|
||||
m.toot(report.text)
|
||||
except Exception:
|
||||
logger.error('Error tooting: ' + user.get_city() + ': ' + report.id, exc_info=True)
|
||||
|
|
15
backend.py
15
backend.py
|
@ -8,9 +8,17 @@ from sendmail import sendmail
|
|||
import time
|
||||
|
||||
|
||||
def shutdown():
|
||||
try:
|
||||
sendmail(config['web']['contact'], 'Ticketfrei Shutdown')
|
||||
except Exception:
|
||||
logger.error('Could not inform admin.', exc_info=True)
|
||||
exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
fh = logging.StreamHandler()
|
||||
fh = logging.FileHandler('/var/log/ticketfrei/backend.log')
|
||||
fh.setLevel(logging.DEBUG)
|
||||
logger.addHandler(fh)
|
||||
|
||||
|
@ -32,7 +40,4 @@ if __name__ == '__main__':
|
|||
time.sleep(60) # twitter rate limit >.<
|
||||
except Exception:
|
||||
logger.error('Shutdown.', exc_info=True)
|
||||
try:
|
||||
sendmail(config['web']['contact'], 'Ticketfrei Shutdown')
|
||||
except Exception:
|
||||
logger.error('Could not inform admin.', exc_info=True)
|
||||
shutdown()
|
||||
|
|
1
db.py
1
db.py
|
@ -31,6 +31,7 @@ class DB(object):
|
|||
CREATE TABLE IF NOT EXISTS user (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
passhash TEXT,
|
||||
city TEXT,
|
||||
enabled INTEGER DEFAULT 1
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS email (
|
||||
|
|
|
@ -13,7 +13,7 @@ class Report(object):
|
|||
Constructor of a ticketfrei report
|
||||
|
||||
:param author: username of the author
|
||||
:param source: mastodon, twitter, or email
|
||||
:param source: mastodon, twitter, or email bot object
|
||||
:param text: the text of the report
|
||||
:param id: id in the network
|
||||
:param timestamp: time of the report
|
||||
|
|
4
user.py
4
user.py
|
@ -172,3 +172,7 @@ class User(object):
|
|||
db.execute("INSERT INTO mastodon_accounts(user_id, access_token, instance_id, active) "
|
||||
"VALUES(?, ?, ?, ?);", (self.uid, access_token, instance_id, 1))
|
||||
db.commit()
|
||||
|
||||
def get_city(self):
|
||||
db.execute("SELECT city FROM user WHERE id == ?;", (self.uid, ))
|
||||
return db.cur.fetchone()[0]
|
||||
|
|
Loading…
Reference in a new issue