From 53533e18216d327aa7b0f0f9be6e6642d65726ef Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 11 Dec 2011 01:58:04 -0500 Subject: [PATCH] Support for a hidden date sortkey. Also fixing a bug in get_notes() with regards to the 'old' note/warning. --- earwigbot/tasks/afc_statistics.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/earwigbot/tasks/afc_statistics.py b/earwigbot/tasks/afc_statistics.py index 0328bce..9c35fdc 100644 --- a/earwigbot/tasks/afc_statistics.py +++ b/earwigbot/tasks/afc_statistics.py @@ -163,20 +163,29 @@ class Task(BaseTask): table, where keys are column names and values are their cell contents. """ row = "{0}|s={page_status}|t={page_title}|h={page_short}|z={page_size}|" - row += "sr={page_special_user}|sd={page_special_time}|si={page_special_oldid}|" - row += "mr={page_modify_user}|md={page_modify_time}|mi={page_modify_oldid}" + row += "sr={page_special_user}|sh={page_special_hidden}|sd={page_special_time}|si={page_special_oldid}|" + row += "mr={page_modify_user}|mh={page_modify_hidden}|md={page_modify_time}|mi={page_modify_oldid}" page["page_special_time"] = self.format_time(page["page_special_time"]) page["page_modify_time"] = self.format_time(page["page_modify_time"]) + page["page_special_hidden"] = self.format_hidden(page["page_special_time"]) + page["page_modify_hidden"] = self.format_hidden(page["page_modify_time"]) if page["page_notes"]: row += "|n=1{page_notes}" return "".join(("{{", row.format(self.tl_row, **page), "}}")) - def format_time(self, timestamp): + def format_time(self, dt): """Format a datetime into the standard MediaWiki timestamp format.""" - return timestamp.strftime("%H:%M, %d %b %Y") + return dt.strftime("%H:%M, %d %b %Y") + + def format_hidden(self, dt): + """Convert a datetime into seconds since the epoch. + + This is used by the template as a hidden sortkey. + """ + return (dt - datetime(1970, 1, 1)).total_seconds() def sync(self, **kwargs): """Synchronize our local statistics database with the site. @@ -691,7 +700,7 @@ class Task(BaseTask): else: notes += "|nu=1" # Submission is completely unsourced - time_since_modify = (datetime.now() - m_time).seconds + time_since_modify = (datetime.now() - m_time).total_seconds() max_time = 4 * 24 * 60 * 60 if time_since_modify > max_time: notes += "|no=1" # Submission hasn't been touched in over 4 days