Revision: 3972
Author: wikipedian
Date: 2007-08-06 16:13:28 +0000 (Mon, 06 Aug 2007)
Log Message:
-----------
fixed docu
Modified Paths:
--------------
trunk/pywikipedia/basic.py
Modified: trunk/pywikipedia/basic.py
===================================================================
--- trunk/pywikipedia/basic.py 2007-08-06 15:56:08 UTC (rev 3971)
+++ trunk/pywikipedia/basic.py 2007-08-06 16:13:28 UTC (rev 3972)
@@ -1,30 +1,32 @@
-#!/usr/bin/python
+#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This is not a complete bot; rather, it is a template from which simple
-bots can be made. Change workon to edit the contents of a Wikipedia page,
-save the result as mybot.py, and then just run:
+bots can be made. You can rename it to mybot.py, then edit it in
+whatever way you want.
-python mybot.py
+The following parameters are supported:
-to have your change be done on all pages of the wiki. If that takes too
-long to work in one stroke, run:
+¶ms;
-python mybot.py Pagename
+ -debug If given, doesn't do any real changes, but only shows
+ what would have been changed.
-to do all pages starting at pagename.
-
-There is one standard command line option:
-
--debug: Don't do any changes.
+All other parameters will be regarded as part of the title of a single page,
+and the bot will only work on that single page.
"""
__version__ = '$Id$'
import wikipedia
import pagegenerators
import sys
+# This is required for the text that is shown when you run this script
+# with the parameter -help.
+docuReplacements = {
+ '¶ms;': pagegenerators.parameterHelp
+}
+
class BasicBot:
-
# Edit summary message that should be used.
# NOTE: Put a good description here, and add translations, if possible!
msg = {
@@ -37,7 +39,7 @@
Constructor. Parameters:
* generator - The page generator that determines on which pages
to work on.
- * debug - If True, doesn't do any real changes, but only show
+ * debug - If True, doesn't do any real changes, but only shows
what would have been changed.
"""
self.generator = generator
@@ -50,7 +52,11 @@
self.treat(page)
def treat(self, page):
+ """
+ Loads the given page, does some changes, and saves it.
+ """
try:
+ # Load the page
text = page.get()
except wikipedia.NoPage:
wikipedia.output(u"Page %s does not exist; skipping." % page.aslink())
@@ -62,15 +68,17 @@
wikipedia.output(u"Page %s is locked; skipping." % page.aslink())
return
- # NOTE: Here you can modify the text in whatever way you want.
- # If you find you do not want to edit this page, just return
+ ################################################################
+ # NOTE: Here you can modify the text in whatever way you want. #
+ ################################################################
- # Example: This puts the text 'Foobar' at the beginning of the page.
- text = 'Foobar ' + text
+ # If you find out that you do not want to edit this page, just return.
+ # Example: This puts the text 'Test' at the beginning of the page.
+ text = 'Test ' + text
# only save if something was changed
if text != page.get():
- # Show the title of the page where the link was found.
+ # Show the title of the page we're working on.
# Highlight the title in purple.
colors = [None] * 6 + [13] * len(page.title()) + [None] * 4
wikipedia.output(u"\n\n>>> %s <<<" % page.title(), colors = colors)
@@ -80,11 +88,12 @@
choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No'], ['y', 'N'], 'N')
if choice == 'y':
try:
+ # Save the page
page.put(text)
except wikipedia.EditConflict:
wikipedia.output(u'Skipping %s because of edit conflict' % (page.title()))
- except wikipedia.SpamfilterError, e:
- wikipedia.output(u'Cannot change %s because of blacklist entry %s' % (page.title(), e.url))
+ except wikipedia.SpamfilterError, error:
+ wikipedia.output(u'Cannot change %s because of spam blacklist entry %s' % (page.title(), error.url))
def main():
Revision: 3971
Author: wikipedian
Date: 2007-08-06 15:56:08 +0000 (Mon, 06 Aug 2007)
Log Message:
-----------
added docu
Modified Paths:
--------------
trunk/pywikipedia/weblinkchecker.py
Modified: trunk/pywikipedia/weblinkchecker.py
===================================================================
--- trunk/pywikipedia/weblinkchecker.py 2007-08-06 15:51:23 UTC (rev 3970)
+++ trunk/pywikipedia/weblinkchecker.py 2007-08-06 15:56:08 UTC (rev 3971)
@@ -24,6 +24,13 @@
When a link is found alive, it will be removed from the .dat file.
+The following parameters are supported:
+
+¶ms;
+
+All other parameters will be regarded as part of the title of a single page,
+and the bot will only work on that single page.
+
Syntax examples:
python weblinkchecker.py
Loads all wiki pages in alphabetical order using the Special:Allpages
@@ -56,6 +63,10 @@
import httplib, socket, urlparse, urllib, urllib2
import threading, time
+docuReplacements = {
+ '¶ms;': pagegenerators.parameterHelp
+}
+
talk_report_msg = {
'de': u'Bot: Berichte nicht verfügbaren Weblink',
'en': u'robot: Reporting unavailable external link',
Revision: 3970
Author: wikipedian
Date: 2007-08-06 15:51:23 +0000 (Mon, 06 Aug 2007)
Log Message:
-----------
added docu
added warning & prompt that appears when running the script as a
stand-alone
Modified Paths:
--------------
trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py
===================================================================
--- trunk/pywikipedia/cosmetic_changes.py 2007-08-06 15:31:41 UTC (rev 3969)
+++ trunk/pywikipedia/cosmetic_changes.py 2007-08-06 15:51:23 UTC (rev 3970)
@@ -1,16 +1,44 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
"""
This module can do slight modifications to a wiki page source code such that
the code looks cleaner. The changes are not supposed to change the look of the
rendered wiki page.
-WARNING: This module needs more testing!
+The following parameters are supported:
+
+¶ms;
+
+All other parameters will be regarded as part of the title of a single page,
+and the bot will only work on that single page.
+
+&warning;
+
+For regular use, it is recommended to put this line into your user-config.py:
+
+ cosmetic_changes = True
+
+There is another config variable: You can set
+
+ cosmetic_changes_mylang_only = False
+
+if you're running a bot on multiple sites and want to do cosmetic changes on
+all of them, but be careful if you do.
"""
__version__ = '$Id$'
import wikipedia, pagegenerators
import sys
import re
+warning = """ATTENTION: You can run this script as a stand-alone for testing purposes.
+However, the changes are that are made are only minor, and other users
+might get angry if you fill the version histories and watchlists with such
+irrelevant changes."""
+
+docuReplacements = {
+ '¶ms;': pagegenerators.parameterHelp,
+ '&warning;': warning,
+}
+
# Summary message when using this module as a stand-alone script
msg_standalone = {
'de': u'Bot: Kosmetische Änderungen',
@@ -20,7 +48,7 @@
'nl': u'Bot: Cosmetische veranderingen',
'pl': u'Robot dokonuje poprawek kosmetycznych',
'pt': u'Bot: Mudanças triviais',
- }
+}
# Summary message that will be appended to the normal message when
# cosmetic changes are made on the fly
@@ -32,7 +60,7 @@
'nl': u'; cosmetische veranderingen',
'pl': u'; zmiany kosmetyczne',
'pt': u'; mudanças triviais',
- }
+}
deprecatedTemplates = {
'wikipedia': {
@@ -316,19 +344,21 @@
else:
pageTitle.append(arg)
- if wikipedia.getSite() == wikipedia.getSite('nl','wikipedia'):
- print "Deze bot is op WikipediaNL niet gewenst."
- print "Het toevoegen van cosmetic changes bij andere veranderingen is toegestaan,"
- print "maar cosmetic_changes als stand-alone bot niet."
- print "Vind a.u.b. een nuttig gebruik voor uw bot."
- sys.exit()
+ # Disabled this check. Although the point is still valid, there
+ # is now a warning and a prompt (see below).
+ #if wikipedia.getSite() == wikipedia.getSite('nl','wikipedia'):
+ #print "Deze bot is op WikipediaNL niet gewenst."
+ #print "Het toevoegen van cosmetic changes bij andere veranderingen is toegestaan,"
+ #print "maar cosmetic_changes als stand-alone bot niet."
+ #print "Vind a.u.b. een nuttig gebruik voor uw bot."
+ #sys.exit()
if pageTitle:
page = wikipedia.Page(wikipedia.getSite(), ' '.join(pageTitle))
gen = iter([page])
if not gen:
wikipedia.showHelp()
- else:
+ elif wikipedia.inputChoice(warning + '\nDo you really want to continue?', ['yes', 'no'], ['y', 'N'], 'N') == 'y':
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = CosmeticChangesBot(preloadingGen)
bot.run()
Revision: 3969
Author: wikipedian
Date: 2007-08-06 15:31:41 +0000 (Mon, 06 Aug 2007)
Log Message:
-----------
added docu
Modified Paths:
--------------
trunk/pywikipedia/pagegenerators.py
Modified: trunk/pywikipedia/pagegenerators.py
===================================================================
--- trunk/pywikipedia/pagegenerators.py 2007-08-06 11:41:37 UTC (rev 3968)
+++ trunk/pywikipedia/pagegenerators.py 2007-08-06 15:31:41 UTC (rev 3969)
@@ -18,24 +18,58 @@
parameterHelp = """ -cat Work on all pages which are in a specific category.
Argument can also be given as "-cat:categoryname".
+ -file Read a list of pages to treat from the named text file.
+ Page titles in the file must be enclosed with [[brackets]].
+ Argument can also be given as "-file:filename".
+
+ -filelinks Work on all pages that use a certain image/media file.
+ Argument can also be given as "-file:filename".
+
+ -google Work on all pages that are found in a Google search.
+ You need a Google Web API license key. Note that Google
+ doesn't give out license keys anymore. See google_key in
+ config.py for instructions.
+ Argument can also be given as "-google:searchstring".
+
+ -links Work on all pages that are linked from a certain page.
+ Argument can also be given as "-links:linkingpagetitle".
+
+ -new Work on the 60 newest pages. If given as -new:x, will work
+ on the x newest pages.
+
+ -ref Work on all pages that link to a certain page.
+ Argument can also be given as "-ref:referredpagetitle".
+
+ -start Specifies that the robot should go alphabetically through
+ all pages on the home wiki, starting at the named page.
+ Argument can also be given as "-subcat:pagetitle".
+
-subcat Like -cat, but also includes pages in subcategories of the
given category.
Argument can also be given as "-subcat:categoryname".
- -start: Specifies that the robot should go alphabetically through
+ -transcludes Work on all pages that use a certain template.
+ Argument can also be given as "-transcludes:Template:Title".
+
+ -unusedfiles Work on all description pages of images/media files that are
+ not used anywhere.
+ Argument can also be given as "-unusedfiles:n" where
+ n is some number (??).
+
+ -unwatched Work on all articles that are not watched by anyone.
+ Argument can also be given as "-unusedfiles:n" where
+ n is some number (??).
+
+ -weblink Specifies that the robot should go alphabetically through
all pages on the home wiki, starting at the named page.
Argument can also be given as "-subcat:pagetitle".
- -ref Work on all pages that link to a certain page.
- Argument can also be given as "-ref:referredpagetitle".
+ -withoutinterwiki Work on all pages that don't have interlanguage links.
+ Argument can also be given as "-withoutinterwiki:n" where
+ n is some number (??).
+"""
- -links Work on all pages that are linked from a certain page.
- Argument can also be given as "-links:linkingpagetitle".
- -file: used as -file:filename, read a list of pages to treat
- from the named text file.
- Page titles in the file must be enclosed with [[brackets]].
- Argument can also be given as "-file:filename"."""
docuReplacements = {
'¶ms;': parameterHelp
@@ -593,7 +627,7 @@
transclusionPageTitle = wikipedia.input(u'Pages that transclude which page should be processed?')
else:
transclusionPageTitle = arg[len('-transcludes:'):]
- transclusionPage = wikipedia.Page(wikipedia.getSite(), transclusionPageTitle)
+ transclusionPage = wikipedia.Page(wikipedia.getSite(), 'Template:%s' % transclusionPageTitle)
gen = ReferringPageGenerator(transclusionPage, onlyTemplateInclusion = True)
elif arg.startswith('-start'):
if len(arg) == 6:
@@ -622,12 +656,16 @@
if __name__ == "__main__":
try:
+ gen = None
genFactory = GeneratorFactory()
for arg in wikipedia.handleArgs():
generator = genFactory.handleArg(arg)
if generator:
gen = generator
- for page in gen:
- wikipedia.output(page.title(), toStdout = True)
+ if gen:
+ for page in gen:
+ wikipedia.output(page.title(), toStdout = True)
+ else:
+ wikipedia.showHelp('pagegenerators')
finally:
wikipedia.stopme()
Revision: 3967
Author: wikipedian
Date: 2007-08-06 10:42:27 +0000 (Mon, 06 Aug 2007)
Log Message:
-----------
experimental, unfinished: added a way to include a docstring from
pagegenerators.py.
Modified Paths:
--------------
trunk/pywikipedia/interwiki.py
trunk/pywikipedia/pagegenerators.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py 2007-08-06 10:41:41 UTC (rev 3966)
+++ trunk/pywikipedia/interwiki.py 2007-08-06 10:42:27 UTC (rev 3967)
@@ -10,6 +10,9 @@
original page will be automatically updated and the modified page uploaded.
This script understands various command-line arguments:
+
+&pagegenerators_help;
+
-force: do not ask permission to make "controversial" changes,
like removing a language because none of the found
alternatives actually exists.
@@ -26,19 +29,6 @@
20:, 30:, 50: Analogous to 10: with ca. 20, 30 and 50 languages
cyril: Provides the hint for all languages that use the cyrillic alphabet
- -cat Work on all pages which are in a specific category.
- Argument can also be given as "-cat:categoryname".
-
- -subcat Like -cat, but also includes pages in subcategories of the
- given category.
- Argument can also be given as "-subcat:categoryname".
-
- -ref Work on all pages that link to a certain page.
- Argument can also be given as "-ref:referredpagetitle".
-
- -links Work on all pages that are linked from a certain page.
- Argument can also be given as "-links:linkingpagetitle".
-
-new Work on the most recent new pages on the wiki
-same: looks over all 'serious' languages for the same title.
@@ -62,9 +52,6 @@
you will go through the whole alphabet before any queries
are performed!
- -file: used as -file:filename, read a list of pages to treat
- from the named file
-
-confirm: ask for confirmation before any page is changed on the
live wiki. Without this argument, additions and
unambiguous modifications are made without confirmation.
@@ -81,12 +68,6 @@
-nobacklink: switch off the backlink warnings
- -start: used as -start:title, specifies that the robot should
- go alphabetically through all pages on the home wiki,
- starting at the named page. If -start:title and -cat:category
- are both added, go through category category, but start
- alphabetically at pagename title instead of the beginning.
-
-number: used as -number:#, specifies that the robot should process
that amount of pages and then stop. This is only useful in
combination with -start. The default is not to stop.
@@ -104,7 +85,7 @@
negative value, it is interpreted as a year BC. If the
argument is simply given as -years, it will run from 1
through 2050.
-
+
This implies -noredirect.
-noauto: Do not use the automatic translation feature for years and
@@ -116,11 +97,10 @@
argument is simply given as -days, it will run from
Jan 1 through Dec 31. E.g. for -days:9 it will run
from Sep 1 through Dec 31.
-
+
-skipfile: used as -skipfile:filename, skip all links mentioned in
- the given file from the list generated by -start. This
- does not work with -number!
-
+ the given file. This does not work with -number!
+
-skipauto: use to skip all pages that can be translated automatically,
like dates, centuries, months, etc.
@@ -153,7 +133,7 @@
-ignorefile: similar to -ignore, except that the pages are taken from
the given file instead of the command line.
-
+
-showpage when asking for hints, show the first bit of the text
of the page always, rather than doing so only when being
asked for (by typing '?'). Only useful in combination
@@ -162,7 +142,7 @@
-localonly only work on the local wiki, not on other wikis in the family
I have a login at
-
+
-limittwo only update two pages - one in the local wiki (if loged-in),
and one in the top available one.
For example, if the local page has links to de and fr,
@@ -180,7 +160,7 @@
(for example -whenneeded:3), in which case other languages
will be changed if there are that number or more links to
change or add
-
+
-bracket only work on pages that have (in the home language) a bracket
in their title. All other pages are skipped.
@@ -218,6 +198,7 @@
#
__version__ = '$Id$'
#
+
import sys, copy, re
import time
import codecs
@@ -252,6 +233,10 @@
import wikipedia, config, pagegenerators, catlib
import titletranslate, interwiki_graph
+docuReplacements = {
+ '&pagegenerators_help;': pagegenerators.parameterHelp
+}
+
class SaveError(wikipedia.Error):
"""
An attempt to save a page with changed interwiki has failed.
Modified: trunk/pywikipedia/pagegenerators.py
===================================================================
--- trunk/pywikipedia/pagegenerators.py 2007-08-06 10:41:41 UTC (rev 3966)
+++ trunk/pywikipedia/pagegenerators.py 2007-08-06 10:42:27 UTC (rev 3967)
@@ -6,10 +6,42 @@
that yields page objects on which other scripts can then work.
In general, there is no need to run this script directly. It can, however,
-be run for testing purposes.
+be run for testing purposes. It will then print the page titles to standard
+output.
+
+These parameters are supported to specify which pages titles to print:
+
+¶ms;
"""
__version__='$Id$'
+parameterHelp = """ -cat Work on all pages which are in a specific category.
+ Argument can also be given as "-cat:categoryname".
+
+ -subcat Like -cat, but also includes pages in subcategories of the
+ given category.
+ Argument can also be given as "-subcat:categoryname".
+
+ -start: Specifies that the robot should go alphabetically through
+ all pages on the home wiki, starting at the named page.
+ Argument can also be given as "-subcat:pagetitle".
+
+ -ref Work on all pages that link to a certain page.
+ Argument can also be given as "-ref:referredpagetitle".
+
+ -links Work on all pages that are linked from a certain page.
+ Argument can also be given as "-links:linkingpagetitle".
+
+ -file: used as -file:filename, read a list of pages to treat
+ from the named text file.
+ Page titles in the file must be enclosed with [[brackets]].
+ Argument can also be given as "-file:filename"."""
+
+docuReplacements = {
+ '¶ms;': parameterHelp
+}
+
+
# Standard library imports
import re, codecs, sys
import threading, Queue
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-08-06 10:41:41 UTC (rev 3966)
+++ trunk/pywikipedia/wikipedia.py 2007-08-06 10:42:27 UTC (rev 3967)
@@ -4531,7 +4531,7 @@
except ValueError: # There was no \ in the module name, so presumably no problem
pass
globalHelp =u'''
-
+
Global arguments available for all bots:
-lang:xx Set the language of the wiki you want to work on, overriding
@@ -4558,8 +4558,13 @@
output(globalHelp)
try:
exec('import %s as module' % moduleName)
- output(module.__doc__, 'utf-8')
+ helpText = module.__doc__.decode('utf-8')
+ if hasattr(module, 'docuReplacements'):
+ for key, value in module.docuReplacements.iteritems():
+ helpText = helpText.replace(key, value)
+ output(helpText)
except:
+ raise
output(u'Sorry, no help available for %s' % moduleName)
page_put_queue = Queue.Queue()
I am curious about something: I know there is at least one person on the English Wikipedia running weblinkchecker.py with the talk page notification feature. I've been intending to do the same thing myself, and for the last 6-12 months (read: a really really long time), I've been running weblinkchecker with notification turned off. If I turn notification on, will these two bots possibly clash by putting duplicate notifications on talk pages?
(I don't want to ask for a bot account until I know there are no ill effects, and I can't test that there are no ill effects without an account.)
--
gwern
Halibut USCODE intelligence Kilderkin ISEP domestic Flintlock Thanatos Amherst 50MZ