diff --git a/bot/commands/replag.py b/bot/commands/replag.py new file mode 100644 index 0000000..448555e --- /dev/null +++ b/bot/commands/replag.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from os.path import expanduser + +import oursql + +from classes import BaseCommand + +class Command(BaseCommand): + """Return the replag for a specific database on the Toolserver.""" + name = "replag" + + def process(self, data): + args = {} + if not data.args: + args["db"] = "enwiki_p" + else: + args["db"] = data.args[0] + args["host"] = args["db"].replace("_", "-") + ".rrdb.toolserver.org" + args["read_default_file"] = expanduser("~/.my.cnf") + + conn = oursql.connect(**args) + with conn.cursor() as cursor: + cursor.execute("SELECT NOW() - MAX(rev_timestamp) FROM revision") + replag = cursor.fetchall()[0][0] + conn.close() + + msg = "Replag on \x0302{0}\x0301 is \x02{1}\x0F seconds." + self.connection.reply(data, msg.format(args["db"], replag)) diff --git a/bot/tasks/afc_history.py b/bot/tasks/afc_history.py index d445beb..e7a627f 100644 --- a/bot/tasks/afc_history.py +++ b/bot/tasks/afc_history.py @@ -4,6 +4,8 @@ from datetime import datetime, timedelta from os.path import expanduser from threading import Lock +import oursql + from classes import BaseTask import config import wiki