Просмотр исходного кода

framework-y stuff for AFC statistics bot

tags/v0.1^2
Ben Kurtovic 13 лет назад
Родитель
Сommit
e61a1367e3
4 измененных файлов: 60 добавлений и 15 удалений
  1. +3
    -0
      .gitignore
  2. +1
    -1
      bot/commands/rights.py
  3. +8
    -8
      bot/rules.py
  4. +48
    -6
      bot/tasks/afc_statistics.py

+ 3
- 0
.gitignore Просмотреть файл

@@ -7,6 +7,9 @@ config.json
# Ignore cookies file:
.cookies

# Ignore statistics file:
statistics.txt

# Ignore OS X's crud:
.DS_Store



+ 1
- 1
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):


+ 8
- 8
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):


+ 48
- 6
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

Загрузка…
Отмена
Сохранить