jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1044480?usp=email )

Change subject: [IMPR] Add -always option to illustrate_wikidata.py
......................................................................

[IMPR] Add -always option to illustrate_wikidata.py

Bug: T367518
Change-Id: Idfc2f2825797dc520c893f97cd4b6a2ba527b1d3
---
M scripts/illustrate_wikidata.py
1 file changed, 30 insertions(+), 25 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index bf6730f..67ca848 100755
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -1,10 +1,15 @@
 #!/usr/bin/env python3
-"""
-Bot to add images to Wikidata items.
+"""Bot to add images to Wikidata items.

 The image is extracted from the page_props. For this to be available the
-PageImages extension (https://www.mediawiki.org/wiki/Extension:PageImages)
-needs to be installed
+PageImages extension
+(https://www.mediawiki.org/wiki/Extension:PageImages) needs to be
+installed.
+
+The following options are provided:
+
+-always    Don't prompt to make changes, just do them.
+-property  The property to add. Should be of type commonsMedia.

 Usage:

@@ -30,19 +35,19 @@

     """A bot to add Wikidata image claims."""

-    def __init__(self, wdproperty: str = 'P18', **kwargs) -> None:
-        """Initializer.
+    update_options = {
+        'property': 'P18',
+    }

-        :param wdproperty: The property to add. Should be of type commonsMedia
-        """
+    def __init__(self, **kwargs) -> None:
+        """Initializer."""
         super().__init__(**kwargs)
-        self.wdproperty = wdproperty
         self.cacheSources()

-        claim = pywikibot.Claim(self.repo, self.wdproperty)
+        claim = pywikibot.Claim(self.repo, self.opt.property)
         if claim.type != 'commonsMedia':
-            raise ValueError('{} is of type {}, should be commonsMedia'
-                             .format(self.wdproperty, claim.type))
+            raise ValueError(f'{self.opt.property} is of type {claim.type},'
+                             ' should be commonsMedia')

     def treat_page_and_item(self, page, item) -> None:
         """Treat a page / item."""
@@ -53,12 +58,12 @@
             return

         claims = item.get().get('claims')
-        if self.wdproperty in claims:
-            pywikibot.info('Item {} already contains image ({})'
-                           .format(item.title(), self.wdproperty))
+        if self.opt.property in claims:
+            pywikibot.info(f'Item {item.title()} already contains image '
+                           f'({self.opt.property})')
             return

-        newclaim = pywikibot.Claim(self.repo, self.wdproperty)
+        newclaim = pywikibot.Claim(self.repo, self.opt.property)
         commonssite = pywikibot.Site('commons')
         imagelink = pywikibot.Link(imagename, source=commonssite,
                                    default_namespace=6)
@@ -87,20 +92,20 @@
     local_args = pywikibot.handle_args(args)
     generator_factory = pagegenerators.GeneratorFactory()

-    wdproperty = 'P18'
+    options = {}

     for arg in local_args:
-        if arg.startswith('-property'):
-            if len(arg) == 9:
-                wdproperty = pywikibot.input(
-                    'Please enter the property you want to add:')
-            else:
-                wdproperty = arg[10:]
+        opt, _, value = arg.partition(':')
+        if opt == '-property':
+            options['property'] = value or pywikibot.input(
+                'Please enter the property you want to add:')
+        elif opt == '-always':
+            options[opt[1:]] = True
         else:
             generator_factory.handle_arg(arg)
 
-    generator = generator_factory.getCombinedGenerator(preload=True)
-    bot = IllustrateRobot(wdproperty, generator=generator)
+    options['generator'] = generator_factory.getCombinedGenerator(preload=True)
+    bot = IllustrateRobot(**options)
     bot.run()



--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1044480?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Idfc2f2825797dc520c893f97cd4b6a2ba527b1d3
Gerrit-Change-Number: 1044480
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to