jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822083 )
Change subject: [doc] Document -inverse argument with an example
......................................................................
[doc] Document -inverse argument with an example
Bug: T314889
Change-Id: I71c491fdff6a4ba9a990a3dc205f586c027798ad
---
M scripts/harvest_template.py
1 file changed, 28 insertions(+), 17 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index b85f714..54552af 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -48,48 +48,59 @@
Examples
--------
-This will try to import existing images from "image" parameter of "Infobox
-person" on English Wikipedia as Wikidata property "P18" (image):
+The following command will try to import existing images from "image"
+parameter of "Infobox person" on English Wikipedia as Wikidata property
+"P18" (image):
python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
-template:"Infobox person" image P18
-This will behave the same as the previous example and also try to import
-[[links]] from "birth_place" parameter of the same template as Wikidata
-property "P19" (place of birth):
+The following command will behave the same as the previous example and also
+try to import [[links]] from "birth_place" parameter of the same template
+as Wikidata property "P19" (place of birth):
python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
-template:"Infobox person" image P18 birth_place P19
-This will import both "birth_place" and "death_place" params with -islink
-modifier, ie. the bot will try to import values, even if it doesn't find
-a [[link]]:
+The following command will import both "birth_place" and "death_place"
+params with -islink modifier, ie. the bot will try to import values, even
+if it doesn't find a [[link]]:
python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
-template:"Infobox person" -islink birth_place P19 death_place P20
-This will do the same but only "birth_place" can be imported without a link:
+The following command will do the same but only "birth_place" can be
+imported without a link:
python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
-template:"Infobox person" birth_place P19 -islink death_place P20
-This will import an occupation from "occupation" parameter of "Infobox
-person" on English Wikipedia as Wikidata property "P106" (occupation). The
-page won't be skipped if the item already has that property but there is
-not the new value:
+The following command will import an occupation from "occupation" parameter
+of "Infobox person" on English Wikipedia as Wikidata property "P106"
+(occupation). The page won't be skipped if the item already has that
+property but there is not the new value:
python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
-template:"Infobox person" occupation P106 -exists:p
-This will import band members from the "current_members" parameter of "Infobox
-musical artist" on English Wikipedia as Wikidata property "P527" (has
-part). This will only extract multiple band members if each is linked, and
-will not add duplicate claims for the same member:
+The following command will import band members from the "current_members"
+parameter of "Infobox musical artist" on English Wikipedia as Wikidata
+property "P527" (has part). This will only extract multiple band members
+if each is linked, and will not add duplicate claims for the same member:
python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
-template:"Infobox musical artist" current_members P527 -exists:p \
-multi
+The following command will import the category's main topic from the first
+anonymous parameter of "Cat main" on English Wikipedia as Wikidata property
+"P301" (category's main topic) and whenever a new value is imported,
+the inverse claim is imported to the topic item as Wikidata property "P910"
+(topic's main category) unless a claim of that property is already there:
+
+ python pwb.py harvest_template -lang:en -family:wikipedia -namespace:14 \
+ -template:"Cat main" 1 P301 -inverse:P910 -islink
+
.. note:: This script is a
:py:obj:`ConfigParserBot <bot.ConfigParserBot>`. All options
can be set within a settings file which is scripts.ini by default.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822083
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I71c491fdff6a4ba9a990a3dc205f586c027798ad
Gerrit-Change-Number: 822083
Gerrit-PatchSet: 3
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822082 )
Change subject: Fix typo
......................................................................
Fix typo
Change-Id: I5e1a98097cf2b9ef02447058af8f082adbfb8120
---
M tests/script_tests.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index cbed98f..e45d1e5 100755
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -100,7 +100,7 @@
# Some of these are not pretty, but at least they are informative
# and not backtraces starting deep in the pywikibot package.
no_args_expected_results = {
- 'archivebot': 'No template was spcified, using default',
+ 'archivebot': 'No template was specified, using default',
# TODO: until done here, remember to set editor = None in user-config.py
'change_pagelang': 'No -setlang parameter given',
'checkimages': 'Execution time: 0 seconds',
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822082
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5e1a98097cf2b9ef02447058af8f082adbfb8120
Gerrit-Change-Number: 822082
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822044 )
Change subject: Revert pairwise usage in several scripts
......................................................................
Revert pairwise usage in several scripts
pairwise is overlapping which is not appropriate in these cases.
This partly reverts commit d4ab3d26ae476983cbd38829b711ceaa19aaf75b.
Change-Id: I938f703408a161f0d4f7b803c0ae0ab418a1f76c
---
M scripts/claimit.py
M scripts/replace.py
M scripts/template.py
3 files changed, 18 insertions(+), 18 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/claimit.py b/scripts/claimit.py
index 4fff795..3e1ac09 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -52,7 +52,6 @@
#
import pywikibot
from pywikibot import WikidataBot, pagegenerators
-from pywikibot.backports import pairwise
# This is required for the text that is shown when you run this script
@@ -127,15 +126,15 @@
claims = []
repo = pywikibot.Site().data_repository()
- for source_str, target_str in pairwise(commandline_claims):
- claim = pywikibot.Claim(repo, source_str)
+ for i in range(0, len(commandline_claims), 2):
+ claim = pywikibot.Claim(repo, commandline_claims[i])
if claim.type == 'wikibase-item':
- target = pywikibot.ItemPage(repo, target_str)
+ target = pywikibot.ItemPage(repo, commandline_claims[i + 1])
elif claim.type == 'string':
- target = target_str
+ target = commandline_claims[i + 1]
elif claim.type == 'globe-coordinate':
coord_args = [
- float(c) for c in target_str.split(',')]
+ float(c) for c in commandline_claims[i + 1].split(',')]
if len(coord_args) >= 3:
precision = coord_args[2]
else:
diff --git a/scripts/replace.py b/scripts/replace.py
index 703dd5c..ac97270 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -154,7 +154,7 @@
import pywikibot
from pywikibot import editor, fixes, i18n, pagegenerators, textlib
-from pywikibot.backports import pairwise, Dict, Generator, List, Pattern, Tuple
+from pywikibot.backports import Dict, Generator, List, Pattern, Tuple
from pywikibot.bot import ExistingPageBot, SingleSiteBot
from pywikibot.exceptions import InvalidPageError, NoPageError
from pywikibot.tools import chars
@@ -979,9 +979,9 @@
# The summary stored here won't be actually used but is only an example
site = pywikibot.Site()
single_summary = None
-
- for old, new in pairwise(commandline_replacements):
- replacement = Replacement(old, new)
+ for i in range(0, len(commandline_replacements), 2):
+ replacement = Replacement(commandline_replacements[i],
+ commandline_replacements[i + 1])
if not single_summary:
single_summary = i18n.twtranslate(
site, 'replace-replacing',
diff --git a/scripts/template.py b/scripts/template.py
index 58421bd..7e83f71 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -113,7 +113,6 @@
import pywikibot
from pywikibot import i18n, pagegenerators, textlib
-from pywikibot.backports import pairwise
from pywikibot.bot import SingleSiteBot
from pywikibot.pagegenerators import XMLDumpPageGenerator
from pywikibot.tools.itertools import filter_unique, roundrobin_generators
@@ -216,6 +215,7 @@
:param args: command line arguments
"""
template_names = []
+ templates = {}
options = {}
# If xmlfilename is None, references will be loaded from the live wiki.
xmlfilename = None
@@ -266,16 +266,17 @@
return
if bool(options.get('subst', False)) ^ options.get('remove', False):
- templates = {name: None for name in template_names}
+ for template_name in template_names:
+ templates[template_name] = None
else:
- if len(template_names) % 2:
- pywikibot.warning('Unless using solely -subst or -remove, you'
- 'must give an even number of template names.')
+ try:
+ for i in range(0, len(template_names), 2):
+ templates[template_names[i]] = template_names[i + 1]
+ except IndexError:
+ pywikibot.output('Unless using solely -subst or -remove, '
+ 'you must give an even number of template names.')
return
- templates = {key: value
- for key, value in pairwise(template_names)}
-
old_templates = [pywikibot.Page(site, template_name, ns=10)
for template_name in templates]
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822044
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I938f703408a161f0d4f7b803c0ae0ab418a1f76c
Gerrit-Change-Number: 822044
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822038 )
Change subject: [tests] Add archivebot tests to auto_run_script_list
......................................................................
[tests] Add archivebot tests to auto_run_script_list
Change-Id: I999a2a2d1a038d4d20a86f70cc41b84cc4d195b0
---
M tests/script_tests.py
1 file changed, 2 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 0080f53..cbed98f 100755
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -76,6 +76,7 @@
}
auto_run_script_list = [
+ 'archivebot',
'blockpageschecker',
'category_redirect',
'checkimages',
@@ -99,6 +100,7 @@
# Some of these are not pretty, but at least they are informative
# and not backtraces starting deep in the pywikibot package.
no_args_expected_results = {
+ 'archivebot': 'No template was spcified, using default',
# TODO: until done here, remember to set editor = None in user-config.py
'change_pagelang': 'No -setlang parameter given',
'checkimages': 'Execution time: 0 seconds',
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/822038
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I999a2a2d1a038d4d20a86f70cc41b84cc4d195b0
Gerrit-Change-Number: 822038
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/821799 )
Change subject: [bugfix] timestripper should skip HTML elements
......................................................................
[bugfix] timestripper should skip HTML elements
Remove HTML elements before searching for timestamp in text.
Also fix isort check.
Bug: T302496
Change-Id: Iad70c4dd803fd40aac6f8d100c80512a876ea724
---
M pywikibot/textlib.py
M tests/timestripper_tests.py
2 files changed, 12 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index cc94eaf..d6eab05 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -25,7 +25,7 @@
from pywikibot.exceptions import InvalidTitleError, SiteDefinitionError
from pywikibot.family import Family
from pywikibot.time import TZoneFixedOffset
-from pywikibot.tools import deprecated, ModuleDeprecationWrapper
+from pywikibot.tools import ModuleDeprecationWrapper, deprecated
from pywikibot.userinterfaces.transliteration import NON_LATIN_DIGITS
@@ -2016,6 +2016,7 @@
# Remove parts that are not supposed to contain the timestamp, in order
# to reduce false positives.
line = removeDisabledParts(line)
+ line = removeHTMLParts(line)
line = to_latin_digits(line)
for pat in self.patterns:
diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py
index b178bac..4929296 100755
--- a/tests/timestripper_tests.py
+++ b/tests/timestripper_tests.py
@@ -377,6 +377,16 @@
txt_match = self.date[:9] + '[[foo]]' + self.date[9:]
self.assertEqual(ts(txt_match), self.expected_date)
+ def test_timestripper_skip_html(self):
+ """Test dates in html are correctly skipped."""
+ ts = self.ts.timestripper
+
+ txt_match = '<div ' + self.fake_date + '>'
+ self.assertIsNone(ts(txt_match))
+
+ txt_match = self.date + '<div ' + self.fake_date + '>'
+ self.assertEqual(ts(txt_match), self.expected_date)
+
class TestTimeStripperDoNotArchiveUntil(TestTimeStripperCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/821799
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Iad70c4dd803fd40aac6f8d100c80512a876ea724
Gerrit-Change-Number: 821799
Gerrit-PatchSet: 2
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged