A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

30 satır
885 B

  1. # -*- coding: utf-8 -*-
  2. from os.path import expanduser
  3. import oursql
  4. from classes import BaseCommand
  5. class Command(BaseCommand):
  6. """Return the replag for a specific database on the Toolserver."""
  7. name = "replag"
  8. def process(self, data):
  9. args = {}
  10. if not data.args:
  11. args["db"] = "enwiki_p"
  12. else:
  13. args["db"] = data.args[0]
  14. args["host"] = args["db"].replace("_", "-") + ".rrdb.toolserver.org"
  15. args["read_default_file"] = expanduser("~/.my.cnf")
  16. conn = oursql.connect(**args)
  17. with conn.cursor() as cursor:
  18. cursor.execute("SELECT NOW() - MAX(rev_timestamp) FROM revision")
  19. replag = int(cursor.fetchall()[0][0])
  20. conn.close()
  21. msg = "Replag on \x0302{0}\x0301 is \x02{1}\x0F seconds."
  22. self.connection.reply(data, msg.format(args["db"], replag))