diff --git a/.gitignore b/.gitignore index ab78225..42c98e0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ config.json # Ignore cookies file: .cookies +# Ignore statistics file: +statistics.txt + # Ignore OS X's crud: .DS_Store diff --git a/bot/commands/rights.py b/bot/commands/rights.py index db436a7..b7011a4 100644 --- a/bot/commands/rights.py +++ b/bot/commands/rights.py @@ -4,7 +4,7 @@ from classes import BaseCommand import wiki class Command(BaseCommand): - """Retrieve a list of rights for a given name.""" + """Retrieve a list of rights for a given username.""" name = "rights" def check(self, data): diff --git a/bot/rules.py b/bot/rules.py index f4a7a71..6388586 100644 --- a/bot/rules.py +++ b/bot/rules.py @@ -36,8 +36,8 @@ def process(rc): chans.update(("##earwigbot", "#wikipedia-en-afc")) if r_page.search(page_name): - tasks.start("afc_statistics", action="process_edit", page=rc.page) - tasks.start("afc_copyvios", action="process_edit", page=rc.page) + tasks.start("afc_statistics", action="edit", page=rc.page) + tasks.start("afc_copyvios", action="edit", page=rc.page) chans.add("#wikipedia-en-afc") elif r_ffu.match(page_name): @@ -49,20 +49,20 @@ def process(rc): elif rc.flags == "move" and (r_move1.match(comment) or r_move2.match(comment)): p = r_moved_pages.findall(rc.comment)[0] - tasks.start("afc_statistics", action="process_move", pages=p) - tasks.start("afc_copyvios", action="process_move", pages=p) + tasks.start("afc_statistics", action="move", page=p) + tasks.start("afc_copyvios", action="move", page=p) chans.add("#wikipedia-en-afc") elif rc.flags == "delete" and r_delete.match(comment): p = r_deleted_page.findall(rc.comment)[0] - tasks.start("afc_statistics", action="process_delete", page=p) - tasks.start("afc_copyvios", action="process_delete", page=p) + tasks.start("afc_statistics", action="delete", page=p) + tasks.start("afc_copyvios", action="delete", page=p) chans.add("#wikipedia-en-afc") elif rc.flags == "restore" and r_restore.match(comment): p = r_restored_page.findall(rc.comment)[0] - tasks.start("afc_statistics", action="process_restore", page=p) - tasks.start("afc_copyvios", action="process_restore", page=p) + tasks.start("afc_statistics", action="restore", page=p) + tasks.start("afc_copyvios", action="restore", page=p) chans.add("#wikipedia-en-afc") elif rc.flags == "protect" and r_protect.match(comment): diff --git a/bot/tasks/afc_statistics.py b/bot/tasks/afc_statistics.py index 2a6ae44..51ffe78 100644 --- a/bot/tasks/afc_statistics.py +++ b/bot/tasks/afc_statistics.py @@ -1,17 +1,59 @@ # -*- coding: utf-8 -*- -import time +from os import path from classes import BaseTask +import config class Task(BaseTask): - """A task to generate statistics for [[WP:AFC]] and save them to - [[Template:AFC_statistics]].""" + """A task to generate statistics for WikiProject Articles for Creation. + + Statistics are stored in the file indicated by self.filename, + "statistics.txt" in the bot's root directory being the default. They are + updated live while watching the recent changes IRC feed. + + The bot saves its statistics once an hour, on the hour, to self.pagename. + In the live bot, this is "Template:AFC statistics". + """ name = "afc_statistics" def __init__(self): - pass + self.filename = path.join(config.root_dir, "statistics.txt") + self.pagename = "User:EarwigBot/Sandbox/Statistics" def run(self, **kwargs): - time.sleep(5) - print kwargs + try: + action = kwargs["action"] + except KeyError: + return + + if action == "save": + self.save() + else: + try: + page = kwargs["page"] + except KeyError: + return + if action == "edit": + self.process_edit(page) + elif action == "move": + self.process_move(page) + elif action == "delete": + self.process_delete(page) + elif action == "restore": + self.process_restore(page) + + def save(self): + pass + + def process_edit(self, page): + pass + + def process_move(self, page): + pass + + def process_delete(self, page): + pass + + def process_restore(self, page): + pass