User:CarpetBot
Jump to navigation
Jump to search
For various mass-edit tasks
Adding text[edit]
To add text to the top of all pages for which the corresponding talk page is in a category (except when the text is already on the page):
python pwb.py add_text -cat:'HIGH priority articles' -up -alwaysmain -summary:'Bot:Adding priority to main page' \
-text:'{{pri|3}}' -noreorder -except:'{{pri\|3}}'
Requires below patch
Patch |
---|
diff --git a/scripts/add_text.py b/scripts/add_text.py
index bfe9365..a16b852 100755
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -16,6 +16,9 @@ Furthermore, the following command line parameters are supported:
-talkpage Put the text onto the talk page instead the generated on
-talk
+-alwaysmain Always put the text on the main page, even if we've matched
+-main a talk page
+
-text Define which text to add. "\n" are interpreted as newlines.
-textfile Define a texfile name which contains the text to add
@@ -120,7 +123,8 @@ starsList = [
def add_text(page, addText, summary=None, regexSkip=None,
regexSkipUrl=None, always=False, up=False, putText=True,
- oldTextGiven=None, reorderEnabled=True, create=False):
+ oldTextGiven=None, reorderEnabled=True, create=False,
+ alwaysMain=False):
"""
Add text to a page.
@@ -293,6 +297,7 @@ def main(*args):
always = False
textfile = None
talkPage = False
+ alwaysMain = False
reorderEnabled = True
# Put the text above or below the text?
@@ -338,6 +343,8 @@ def main(*args):
always = True
elif arg == '-talk' or arg == '-talkpage':
talkPage = True
+ elif arg == '-alwaysmain' or arg == '-main':
+ alwaysMain = True
else:
genFactory.handleArg(arg)
if textfile and not addText:
@@ -353,10 +360,14 @@ def main(*args):
if talkPage:
generator = pagegenerators.PageWithTalkPageGenerator(generator, True)
for page in generator:
+ if alwaysMain and 'Talk' in page.title():
+ page = pywikibot.Page(page.site, page.title().replace('Talk', '').strip())
+
(text, newtext, always) = add_text(page, addText, summary, regexSkip,
regexSkipUrl, always, up, True,
reorderEnabled=reorderEnabled,
- create=talkPage)
+ create=talkPage,
+ alwaysMain=alwaysMain)
if __name__ == "__main__":
main()
|
Misc notes[edit]
Old source from when it used mwapi; may still be of use.