ChartsBot-Module: Move charts.py to chartsbot.py to name like class

Several updates of code to use new modul structure
This commit is contained in:
2015-11-13 13:32:17 +01:00
parent df67d7ca8a
commit 1a06d20a75

View File

@@ -22,18 +22,28 @@
# #
# #
""" """
Provides a class for handling chart lists Bot which automatically updates a ChartsSummaryPage like
[[Portal:Charts_und_Popmusik/Aktuelle_Nummer-eins-Hits]] by reading linked
CountryLists
The following parameters are supported:
&params;
-always If given, request for confirmation of edit is short circuited
Use for unattended run
""" """
from datetime import datetime, timedelta
import locale
from isoweek import Week import locale
import pywikibot import pywikibot
from pywikibot import pagegenerators from pywikibot import pagegenerators
from pywikibot.bot import Bot
import mwparserfromhell as mwparser import mwparserfromhell as mwparser
from summarypage import SummaryPage
# This is required for the text that is shown when you run this script # This is required for the text that is shown when you run this script
# with the parameter -help. # with the parameter -help.
docuReplacements = { docuReplacements = {
@@ -41,25 +51,26 @@ docuReplacements = {
} }
class Charts: class ChartsBot( ):
""" """
Class for handling chart lists Bot which automatically updates a ChartsSummaryPage like
[[Portal:Charts_und_Popmusik/Aktuelle_Nummer-eins-Hits]] by reading linked
CountryListsAn incomplete sample bot.
""" """
def __init__( self, generator, always, dry ): def __init__( self, generator, always ):
""" """
Constructor. Constructor.
@param generator: The page generator that determines on which pages @param generator: the page generator that determines on which pages
to work. to work
@type generator: generator. @type generator: generator
@param dry: If True, doesn't do any real changes, but only shows @param always: if True, request for confirmation of edit is short
what would have been changed. circuited. Use for unattended run
@type dry: boolean. @type always: bool
""" """
self.generator = generator self.generator = generator
self.dry = dry
self.always = always self.always = always
# Set the edit summary message # Set the edit summary message
@@ -84,10 +95,13 @@ class Charts:
# NOTE: Here you can modify the text in whatever way you want. # # NOTE: Here you can modify the text in whatever way you want. #
################################################################ ################################################################
# If you find out that you do not want to edit this page, just return. # Initialise and treat SummaryPageWorker
# Example: This puts the text 'Test' at the beginning of the page. sumpage = SummaryPage( text )
sumpage.treat()
text = self.parse_overview( text ) # Check if editing is needed and if so get new text
if sumpage.get_new_text():
text = sumpage.get_new_text()
if not self.save(text, page, self.summary, False): if not self.save(text, page, self.summary, False):
pywikibot.output(u'Page %s not saved.' % page.title(asLink=True)) pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))
@@ -481,18 +495,13 @@ def main(*args):
genFactory = pagegenerators.GeneratorFactory() genFactory = pagegenerators.GeneratorFactory()
# The generator gives the pages that should be worked upon. # The generator gives the pages that should be worked upon.
gen = None gen = None
# If dry is True, doesn't do any real changes, but only show
# what would have been changed.
dry = False
# If always is True, bot won't ask for confirmation of edit (automode) # If always is True, bot won't ask for confirmation of edit (automode)
always = False always = False
# Parse command line arguments # Parse command line arguments
for arg in local_args: for arg in local_args:
if arg.startswith("-dry"): if arg.startswith("-always"):
dry = True
elif arg.startswith("-always"):
always = True always = True
else: else:
genFactory.handleArg(arg) genFactory.handleArg(arg)
@@ -503,7 +512,7 @@ def main(*args):
# The preloading generator is responsible for downloading multiple # The preloading generator is responsible for downloading multiple
# pages from the wiki simultaneously. # pages from the wiki simultaneously.
gen = pagegenerators.PreloadingGenerator(gen) gen = pagegenerators.PreloadingGenerator(gen)
bot = Charts(gen, always, dry) bot = ChartsBot(gen, always)
bot.run() bot.run()
else: else:
pywikibot.showHelp() pywikibot.showHelp()