Browse Source

Merge branch 'improve-output' into test-v6

(@see https://fs.golderweb.de/index.php?do=details&task_id=20)
develop
Jonathan Golder 8 years ago
parent
commit
2076932cbf
  1. 3
      .gitmodules
  2. 45
      chartsbot.py
  3. 1
      jogobot

3
.gitmodules

@ -0,0 +1,3 @@
[submodule "jogobot"]
path = jogobot
url = ../jogobot

45
chartsbot.py

@ -50,6 +50,8 @@ import locale
import pywikibot import pywikibot
from pywikibot import pagegenerators from pywikibot import pagegenerators
import jogobot
from summarypage import SummaryPage 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
@ -87,6 +89,9 @@ class ChartsBot( ):
# Force parsing of countrylist # Force parsing of countrylist
self.force_reload = force_reload self.force_reload = force_reload
# Output Information
jogobot.output( "Chartsbot invoked" )
# Set the edit summary message # Set the edit summary message
self.site = pywikibot.Site() self.site = pywikibot.Site()
self.summary = "Bot: Aktualisiere Übersichtsseite Nummer-eins-Hits" self.summary = "Bot: Aktualisiere Übersichtsseite Nummer-eins-Hits"
@ -126,7 +131,7 @@ class ChartsBot( ):
text = 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)) jogobot.output(u'Page %s not saved.' % page.title(asLink=True))
def load(self, page): def load(self, page):
"""Load the text of the given page.""" """Load the text of the given page."""
@ -134,11 +139,11 @@ class ChartsBot( ):
# Load the page # Load the page
text = page.get() text = page.get()
except pywikibot.NoPage: except pywikibot.NoPage:
pywikibot.output(u"Page %s does not exist; skipping." jogobot.output( u"Page %s does not exist; skipping."
% page.title(asLink=True)) % page.title(asLink=True), "ERROR" )
except pywikibot.IsRedirectPage: except pywikibot.IsRedirectPage:
pywikibot.output(u"Page %s is a redirect; skipping." jogobot.output( u"Page %s is a redirect; skipping."
% page.title(asLink=True)) % page.title(asLink=True), "ERROR" )
else: else:
return text return text
return None return None
@ -148,13 +153,17 @@ class ChartsBot( ):
"""Update the given page with new text.""" """Update the given page with new text."""
# only save if something was changed (and not just revision) # only save if something was changed (and not just revision)
if text != page.get(): if text != page.get():
# Show the title of the page we're working on.
# Highlight the title in purple. # Show diff only in interactive mode or in verbose mode
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" if not self.always or pywikibot.config.verbose_output:
% page.title())
# show what was changed # Show the title of the page we're working on.
pywikibot.showDiff(page.get(), text) # Highlight the title in purple.
pywikibot.output(u'Comment: %s' % comment) jogobot.output( u">>> \03{lightpurple}%s\03{default} <<<"
% page.title())
# show what was changed
pywikibot.showDiff(page.get(), text)
jogobot.output(u'Comment: %s' % comment)
if self.always or pywikibot.input_yn( if self.always or pywikibot.input_yn(
u'Do you want to accept these changes?', u'Do you want to accept these changes?',
@ -165,17 +174,17 @@ class ChartsBot( ):
page.save(summary=comment or self.comment, page.save(summary=comment or self.comment,
minor=minorEdit, botflag=botflag) minor=minorEdit, botflag=botflag)
except pywikibot.LockedPage: except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked; skipping." jogobot.output( u"Page %s is locked; skipping."
% page.title(asLink=True)) % page.title(asLink=True), "ERROR" )
except pywikibot.EditConflict: except pywikibot.EditConflict:
pywikibot.output( jogobot.output(
u'Skipping %s because of edit conflict' u'Skipping %s because of edit conflict'
% (page.title())) % (page.title()), "ERROR")
except pywikibot.SpamfilterError as error: except pywikibot.SpamfilterError as error:
pywikibot.output( jogobot.output(
u'Cannot change %s because of spam blacklist \ u'Cannot change %s because of spam blacklist \
entry %s' entry %s'
% (page.title(), error.url)) % (page.title(), error.url), "ERROR")
else: else:
return True return True
return False return False

1
jogobot

@ -0,0 +1 @@
Subproject commit 0daf72b625bc84a6029f74b37978e57e42237c82
Loading…
Cancel
Save