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:
|
# for the uwsgi deployment:
|
||||||
less /var/log/ticketfrei/uwsgi.log
|
less /var/log/ticketfrei/uwsgi.log
|
||||||
|
|
||||||
|
# for the backend:
|
||||||
|
less /var/log/ticketfrei/backend.log
|
||||||
|
|
||||||
# for the systemd service:
|
# for the systemd service:
|
||||||
less /var/log/syslog
|
less /var/log/syslog
|
||||||
|
|
||||||
|
|
|
@ -34,16 +34,29 @@ class MastodonBot(Bot):
|
||||||
text = re.sub(
|
text = re.sub(
|
||||||
"(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
"(?<=^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9-_]+)",
|
||||||
"", text)
|
"", text)
|
||||||
|
if status['status']['visibility'] == 'public':
|
||||||
mentions.append(Report(status['account']['acct'],
|
mentions.append(Report(status['account']['acct'],
|
||||||
self,
|
self,
|
||||||
text,
|
text,
|
||||||
status['status']['id'],
|
status['status']['id'],
|
||||||
status['status']['created_at']))
|
status['status']['created_at']))
|
||||||
|
else:
|
||||||
|
mentions.append(Report(status['account']['acct'],
|
||||||
|
'mastodonPrivate',
|
||||||
|
text,
|
||||||
|
status['status']['id'],
|
||||||
|
status['status']['created_at']))
|
||||||
return mentions
|
return mentions
|
||||||
|
|
||||||
def post(self, user, report):
|
def post(self, user, report):
|
||||||
m = Mastodon(*user.get_masto_credentials())
|
m = Mastodon(*user.get_masto_credentials())
|
||||||
if report.source == self:
|
if report.source == self:
|
||||||
|
try:
|
||||||
m.status_reblog(report.id)
|
m.status_reblog(report.id)
|
||||||
|
except Exception:
|
||||||
|
logger.error('Error boosting: ' + report.id, exc_info=True)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
m.toot(report.text)
|
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
|
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__':
|
if __name__ == '__main__':
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
fh = logging.StreamHandler()
|
fh = logging.FileHandler('/var/log/ticketfrei/backend.log')
|
||||||
fh.setLevel(logging.DEBUG)
|
fh.setLevel(logging.DEBUG)
|
||||||
logger.addHandler(fh)
|
logger.addHandler(fh)
|
||||||
|
|
||||||
|
@ -32,7 +40,4 @@ if __name__ == '__main__':
|
||||||
time.sleep(60) # twitter rate limit >.<
|
time.sleep(60) # twitter rate limit >.<
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error('Shutdown.', exc_info=True)
|
logger.error('Shutdown.', exc_info=True)
|
||||||
try:
|
shutdown()
|
||||||
sendmail(config['web']['contact'], 'Ticketfrei Shutdown')
|
|
||||||
except Exception:
|
|
||||||
logger.error('Could not inform admin.', exc_info=True)
|
|
||||||
|
|
1
db.py
1
db.py
|
@ -31,6 +31,7 @@ class DB(object):
|
||||||
CREATE TABLE IF NOT EXISTS user (
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
passhash TEXT,
|
passhash TEXT,
|
||||||
|
city TEXT,
|
||||||
enabled INTEGER DEFAULT 1
|
enabled INTEGER DEFAULT 1
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS email (
|
CREATE TABLE IF NOT EXISTS email (
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Report(object):
|
||||||
Constructor of a ticketfrei report
|
Constructor of a ticketfrei report
|
||||||
|
|
||||||
:param author: username of the author
|
: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 text: the text of the report
|
||||||
:param id: id in the network
|
:param id: id in the network
|
||||||
:param timestamp: time of the report
|
: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) "
|
db.execute("INSERT INTO mastodon_accounts(user_id, access_token, instance_id, active) "
|
||||||
"VALUES(?, ?, ?, ?);", (self.uid, access_token, instance_id, 1))
|
"VALUES(?, ?, ?, ?);", (self.uid, access_token, instance_id, 1))
|
||||||
db.commit()
|
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