Revision: 8171 Author: russblau Date: 2010-05-14 19:11:51 +0000 (Fri, 14 May 2010)
Log Message: ----------- Add hook for watching, unwatching pages.
Modified Paths: -------------- branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2010-05-14 18:53:39 UTC (rev 8170) +++ branches/rewrite/pywikibot/site.py 2010-05-14 19:11:51 UTC (rev 8171) @@ -2584,6 +2584,25 @@
#TODO: implement patrol
+ def watchpage(self, page, unwatch=False): + """Add or remove page from watchlist. + + @param unwatch: If True, remove page from watchlist; if False (default), + add it. + @return: True if API returned expected response; False otherwise + + """ + req = api.Request(action="watch", title=page.title(withSection=False)) + if unwatch: + req["unwatch"] = "" + result = req.submit() + if "watch" not in result: + pywikibot.error(u"watchpage: Unexpected API response:\n%s" % result) + return False + watched = result["watch"] + return ((unwatch and "unwatched" in watched) + or (not unwatch and "watched" in result)) + @deprecated("Site().exturlusage") def linksearch(self, siteurl, limit=None): """Backwards-compatible interface to exturlusage()"""