Browse Source

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

develop
Jonathan Golder 8 years ago
parent
commit
f2d431ab84
  1. 2
      __init__.py
  2. 29
      charts.py
  3. 8
      countrylist.py
  4. 11
      summarypage.py

2
__init__.py

@ -3,7 +3,7 @@
#
# __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
# it under the terms of the GNU General Public License as published by

29
charts.py

@ -11,7 +11,7 @@
#
# 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
# it under the terms of the GNU General Public License as published by
@ -94,23 +94,38 @@ class ChartsBot( ):
# Output Information
jogobot.output( "Chartsbot invoked" )
# Set the edit summary message
# Save pywikibot site object
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'
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
def run(self):
"""Process each page from the generator."""
# Count skipped pages (redirect or missing)
skipped = 0
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):
"""Load the given page, does some changes, and saves it."""
text = self.load(page)
if not text:
return
return False
################################################################
# 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):
jogobot.output(u'Page %s not saved.' % page.title(asLink=True))
return True
def load(self, page):
"""Load the text of the given page."""
try:
@ -140,7 +157,7 @@ class ChartsBot( ):
% page.title(asLink=True), "ERROR" )
else:
return text
return None
return False
def save(self, text, page, comment=None, minorEdit=True,
botflag=True):

8
countrylist.py

@ -3,7 +3,7 @@
#
# 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
# it under the terms of the GNU General Public License as published by
@ -34,6 +34,8 @@ from isoweek import Week
import pywikibot
import mwparserfromhell as mwparser
import jogobot
class CountryList():
"""
@ -131,6 +133,10 @@ class CountryList():
# For easy detecting wether we have parsed self
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 ):
"""
Detect wether current entry is on of the belgian (Belgien/Wallonien)

11
summarypage.py

@ -3,7 +3,7 @@
#
# 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
# 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 mwparserfromhell as mwparser
import jogobot
from countrylist import CountryList, CountryListError
@ -145,6 +147,9 @@ class SummaryPageEntry():
# If list is from last year, replace year
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),
current_year )
@ -159,6 +164,10 @@ class SummaryPageEntry():
# If list is from last year, replace year
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,
(current_year - 1) )

Loading…
Cancel
Save