Darthbhyrava has uploaded a new change for review. https://gerrit.wikimedia.org/r/295132
Change subject: Implement pywikibot support for adding thanks to comments on flow boards ...................................................................... Implement pywikibot support for adding thanks to comments on flow boards Add script flow_thanks and supporting code like unit tests and API Call methods to pywikbiot/site.py for enabling thank support for comments on flow boards. Bug: T135411 Change-Id: I199f304ab72670c63da214781ae7f0b9961989a1 --- M pywikibot/site.py A scripts/flow_thanks.py A tests/flow_thanks_tests.py 3 files changed, 138 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/32/295132/1 diff --git a/pywikibot/site.py b/pywikibot/site.py index ce7f628..f5116b8 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -6390,6 +6390,22 @@ comparison = data['compare']['*'] return comparison + # Thanks API calls + @need_extension('Flow') + @need_extension('Thanks') + def thank_flowpost(self, post_id): + """ + Thank a post identified by the given Post ID. + + @param post_id: The ID for a Flow Post + @type post_id: Unicode + """ + token = self.tokens['csrf'] + params = {'action': 'flowthank', 'postid': post_id, 'token': token} + req = self._request(parameters=params) + data = req.submit() + return data + # Flow API calls @need_extension('Flow') def load_board(self, page): diff --git a/scripts/flow_thanks.py b/scripts/flow_thanks.py new file mode 100644 index 0000000..c6c7000 --- /dev/null +++ b/scripts/flow_thanks.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +A script which takes a post ID on a Flow Board and thanks it on behalf of the +user logged in. + +Syntax: python pwb.py thanks -flow_post:[post_id] + +@params; + + -flow_post: The value of the postID to be thanked. + +""" +from __future__ import absolute_import, unicode_literals + +import pywikibot + + +def thank_flow_post(post_id): + """ + Thank the given Post ID on a Flow Board on behalf of the user logged in. + """ + # Login into the side + site = pywikibot.Site() + site.login() + + # Make Thank API call to site, and print result + result = site.thank_flowpost(post_id) + print result + + +def main(*args): + """ + Proces command line arguments and thank the post + """ + local_args = pywikibot.handle_args(args) + for arg in local_args: + option, sep, value = arg.partition(':') + if option == '-flow_post': + post_id = value + thank_flow_post(post_id) + + +if __name__ == "__main__": + main() diff --git a/tests/flow_thanks_tests.py b/tests/flow_thanks_tests.py new file mode 100644 index 0000000..9632835 --- /dev/null +++ b/tests/flow_thanks_tests.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +"""Test suite for the flow based thanks script.""" +# +# (C) Pywikibot team, 2016 +# +# Distributed under the terms of the MIT license. +# +from __future__ import absolute_import, unicode_literals + +import pywikibot + +from scripts.flow_thanks import thank_flow_post +from pywikibot.flow import Board + +from tests.aspects import unittest, TestCase + + +class TestFlowThank(TestCase): + + """Test thanks for revisions.""" + + family = 'test' + code = 'test' + + def test_topic(self): + """ + Method to test thanks for a Flow post + + Note: This approach requires a new topic and flow post to be added atop + the Talk:Sandbox page between reruns, and will fail otherwise. + Alternatively, one could devise a method to use the post_ids list + in a better way. + """ + + # A list which will store ids of posts from Talk:Sandbox, which can be + # thanked. + post_ids = [] + site = pywikibot.Site() + + # Getting the 'Talk:Sandbox' flow page on test:test + page = Board(self.site, 'Talk:Sandbox') + + # Getting the a generator for topics on that page. + topics_list = page.topics(limit=10) + + # The exception handling feature has been added to deal with the + # anomalous nature of 'Topic:Sel4ipu6maqlbm0d' which throws up a error. + # TODO: Fix the above. + try: + # Extracting each topic, and then the posts in each topic, + # and then appending these post_ids to a list. + for topic in topics_list: + post_list = topic.replies() + for post in post_list: + post_ids.append(post.uuid) + except Exception: + pass + + # Checking log before the thanks action + log_initial = site.logevents(logtype='thanks', total=1) + for x in log_initial: + initial_id = x.logid() + + # Thanking the most recent post on Talk:Sandbox + thank_flow_post(post_ids[0]) + + # Checking log for new thanks, and then comparing with earlier log. + log_final = site.logevents(logtype='thanks', total=1) + for x in log_final: + final_id = x.logid() + + # Asserting that the ids are unequal, implying a successful + # thanks action. + self.assertNotEqual(initial_id, final_id) + +if __name__ == "__main__": + unittest.main() -- To view, visit https://gerrit.wikimedia.org/r/295132 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I199f304ab72670c63da214781ae7f0b9961989a1 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Darthbhyrava <hbhyr...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits