Files
jogobot-red/bots/markpages.py
GOLDERWEB – Jonathan Golder c4d8a95672 Implement build_generator-method
Build_generator will add the redfam_talkpages_generator to the
genFactory, build a generator of the genFactory and sets self.gen
which is used as generator for run()

Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=88 FS#88]
2016-08-28 18:13:27 +02:00

123 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# markpages.py
#
# Copyright 2016 GOLDERWEB Jonathan Golder <jonathan@golderweb.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
"""
Bot to mark pages which were/are subjects of redundance discussions
with templates
"""
from datetime import datetime
from pywikibot import pagegenerators
from pywikibot.bot import CurrentPageBot
import jogobot
from lib.redfam import RedFamWorker
class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat()
"""
Bot class to mark pages which were/are subjects of redundance discussions
with templates
"""
def __init__( self, genFactory, **kwargs ):
"""
Constructor
Parameters:
@param genFactory GenFactory with parsed pagegenerator args to
build generator
@type genFactory pagegenerators.GeneratorFactory
@param **kwargs Additional args
@type iterable
"""
# Init attribute
self.__redfams = None # Will hold a generator with our redfams
# We do not use predefined genFactory as there is no sensefull case to
# give a generator via cmd-line for this right now
self.genFactory = pagegenerators.GeneratorFactory()
# Build generator with genFactory
self.build_generator()
# Run super class init with builded generator
super( MarkPagesBot, self ).__init__(generator=self.gen)
@property
def redfams(self):
"""
Holds redfams generator to work on in this bot
"""
# Create generator if not present
if not self.__redfams:
end_after = datetime.strptime(
jogobot.config["red.markpages"]["mark_done_after"],
"%Y-%m-%d" )
self.__redfams = RedFamWorker.gen_by_status_and_ending(
2, end_after)
return self.__redfams
def build_generator( self ):
"""
Builds generator to pass to super class
"""
# Add Talkpages to work on to generatorFactory
self.genFactory.gens.append( self.redfam_talkpages_generator() )
# Set generator to pass to super class
self.gen = pagegenerators.PreloadingGenerator(
self.genFactory.getCombinedGenerator() )
def redfam_talkpages_generator( self ):
"""
Wrappers the redfam.article_generator and
passes it to pagegenerators.PageWithTalkPageGenerator().
Then it iterates over the generator and adds a reference to the
related redfam to each talkpage-object.
"""
for redfam in self.redfams:
# We need the talkpage (and only this) of each existing page
for talkpage in pagegenerators.PageWithTalkPageGenerator(
redfam.article_generator( filter_existing=True ),
return_talk_only=True ):
# Add reference to redfam to talkpages
talkpage.redfam = redfam
yield talkpage
def treat_page( self ):
"""
Handles work on current page
"""
# Here is the place where to do what ever you want
print( self.current_page.title() )