jenkins-bot has submitted this change and it was merged.

Change subject: repository: implement --item
......................................................................


repository: implement --item

To work on a designated set of items.

Change-Id: I0af93853b6ff4892b37d2a5223b95b425cc61848
Signed-off-by: Loic Dachary <l...@dachary.org>
---
M FLOSSbot/repository.py
1 file changed, 25 insertions(+), 7 deletions(-)

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



diff --git a/FLOSSbot/repository.py b/FLOSSbot/repository.py
index 47bb47c..6c3ce4d 100644
--- a/FLOSSbot/repository.py
+++ b/FLOSSbot/repository.py
@@ -46,12 +46,18 @@
     @staticmethod
     def get_parser():
         parser = argparse.ArgumentParser()
-        parser.add_argument(
+        select = parser.add_mutually_exclusive_group()
+        select.add_argument(
             '--filter',
             default='',
             choices=['no-protocol', 'no-preferred'],
             help='filter with a pre-defined query',
         )
+        select.add_argument(
+            '--item',
+            default=[],
+            action='append',
+            help='work on this QID (can be repeated)')
         return parser
 
     @staticmethod
@@ -66,7 +72,7 @@
             modifications is explained below. By default all
             items that have at least one source code repository
             claim are considered. It can be restricted with
-            the --filter option.
+            the --filter or --item options.
 
             A) Protocol
 
@@ -103,7 +109,6 @@
             --filter no-preferred
                   select only the items for which there exists
                   at more than one claim with no preferred rank
-
 
             [1] {doc}
             """.format(doc=FLOSS_doc)),
@@ -183,6 +188,18 @@
         fun("http://wikidata.org/wiki/"; + item.getID() + " " + message)
 
     def run(self):
+        site = pywikibot.Site(self.args.language_code, "wikidata")
+        self.setup_cache(site)
+        if len(self.args.item) > 0:
+            self.run_items(site)
+        else:
+            self.run_query(site)
+
+    def run_items(self, site):
+        for item in self.args.item:
+            self.fixup(site, pywikibot.ItemPage(site, item, 0))
+
+    def run_query(self, site):
         if self.args.filter == 'no-protocol':
             query = """
             SELECT DISTINCT ?item WHERE {
@@ -212,13 +229,14 @@
             """
         query = query + " # " + str(time.time())
         log.debug(query)
-        site = pywikibot.Site(self.args.language_code, "wikidata")
-        self.setup_cache(site)
         for item in pg.WikidataSPARQLPageGenerator(query,
                                                    site=site,
                                                    result_type=list):
-            self.fixup_protocol(site, item)
-            self.fixup_rank(site, item)
+            self.fixup(site, item)
+
+    def fixup(self, site, item):
+        self.fixup_protocol(site, item)
+        self.fixup_rank(site, item)
 
     def fixup_rank(self, site, item):
         item_dict = item.get()

-- 
To view, visit https://gerrit.wikimedia.org/r/310792
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0af93853b6ff4892b37d2a5223b95b425cc61848
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/bots/FLOSSbot
Gerrit-Branch: master
Gerrit-Owner: Dachary <l...@dachary.org>
Gerrit-Reviewer: Dachary <l...@dachary.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to