Merge branch 'fs#67-more-detailed-logs' into test-v7

This commit is contained in:
2016-09-25 15:10:27 +02:00
4 changed files with 41 additions and 9 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
# #
# __init__.py # __init__.py
# #
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de> # Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
+23 -6
View File
@@ -11,7 +11,7 @@
# #
# modified by: # modified by:
# #
# Copyright 2016 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de> # Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -94,23 +94,38 @@ class ChartsBot( ):
# Output Information # Output Information
jogobot.output( "Chartsbot invoked" ) jogobot.output( "Chartsbot invoked" )
# Set the edit summary message # Save pywikibot site object
self.site = pywikibot.Site() self.site = pywikibot.Site()
self.summary = "Bot: Aktualisiere Übersichtsseite Nummer-eins-Hits"
# Define edit summary
self.summary = jogobot.config["charts"]["edit_summary"].strip()
# Make sure summary starts with "Bot:"
if not self.summary[:len("Bot:")] == "Bot:":
self.summary = "Bot: " + self.summary.strip()
# Set locale to 'de_DE.UTF-8' # Set locale to 'de_DE.UTF-8'
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
def run(self): def run(self):
"""Process each page from the generator.""" """Process each page from the generator."""
# Count skipped pages (redirect or missing)
skipped = 0
for page in self.generator: for page in self.generator:
self.treat(page) if not self.treat(page):
skipped += 1
if skipped:
jogobot.output( "Chartsbot finished, {skipped} page(s) skipped"
.format( skipped=skipped ) )
else:
jogobot.output( "Chartsbot finished successfully" )
def treat(self, page): def treat(self, page):
"""Load the given page, does some changes, and saves it.""" """Load the given page, does some changes, and saves it."""
text = self.load(page) text = self.load(page)
if not text: if not text:
return return False
################################################################ ################################################################
# NOTE: Here you can modify the text in whatever way you want. # # NOTE: Here you can modify the text in whatever way you want. #
@@ -127,6 +142,8 @@ class ChartsBot( ):
if not self.save(text, page, self.summary, False): if not self.save(text, page, self.summary, False):
jogobot.output(u'Page %s not saved.' % page.title(asLink=True)) jogobot.output(u'Page %s not saved.' % page.title(asLink=True))
return True
def load(self, page): def load(self, page):
"""Load the text of the given page.""" """Load the text of the given page."""
try: try:
@@ -140,7 +157,7 @@ class ChartsBot( ):
% page.title(asLink=True), "ERROR" ) % page.title(asLink=True), "ERROR" )
else: else:
return text return text
return None return False
def save(self, text, page, comment=None, minorEdit=True, def save(self, text, page, comment=None, minorEdit=True,
botflag=True): botflag=True):
+7 -1
View File
@@ -3,7 +3,7 @@
# #
# countrylist.py # countrylist.py
# #
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de> # Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -34,6 +34,8 @@ from isoweek import Week
import pywikibot import pywikibot
import mwparserfromhell as mwparser import mwparserfromhell as mwparser
import jogobot
class CountryList(): class CountryList():
""" """
@@ -131,6 +133,10 @@ class CountryList():
# For easy detecting wether we have parsed self # For easy detecting wether we have parsed self
self.parsed = True self.parsed = True
# Log parsed page
jogobot.output( "Parsed revision {revid} of page [[{title}]]".format(
revid=self.revid, title=self.page.title() ) )
def detect_belgian( self ): def detect_belgian( self ):
""" """
Detect wether current entry is on of the belgian (Belgien/Wallonien) Detect wether current entry is on of the belgian (Belgien/Wallonien)
+10 -1
View File
@@ -3,7 +3,7 @@
# #
# summarypage.py # summarypage.py
# #
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de> # Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -30,6 +30,8 @@ from datetime import datetime, timedelta
# import pywikibot # import pywikibot
import mwparserfromhell as mwparser import mwparserfromhell as mwparser
import jogobot
from countrylist import CountryList, CountryListError from countrylist import CountryList, CountryListError
@@ -145,6 +147,9 @@ class SummaryPageEntry():
# If list is from last year, replace year # If list is from last year, replace year
if (current_year - 1) in self.countrylist_wikilink.title: if (current_year - 1) in self.countrylist_wikilink.title:
jogobot.output( "Trying to use new years list for [[{page}]]"
.format( page=self.countrylist_wikilink.title ) )
self.countrylist_wikilink.title.replace( (current_year - 1), self.countrylist_wikilink.title.replace( (current_year - 1),
current_year ) current_year )
@@ -159,6 +164,10 @@ class SummaryPageEntry():
# If list is from last year, replace year # If list is from last year, replace year
if (current_year ) in self.countrylist_wikilink.title: if (current_year ) in self.countrylist_wikilink.title:
jogobot.output( "New years list for [[{page}]] does not " +
"exist, fall back to old list!".format(
page=self.countrylist_wikilink.title ) )
self.countrylist_wikilink.title.replace( current_year, self.countrylist_wikilink.title.replace( current_year,
(current_year - 1) ) (current_year - 1) )