Manual:Pywikibot/watchlist.py
From Linux Web Expert
File:Git icon.svg | <translate> Wikimedia [[<tvar|1>Special:MyLanguage/Gerrit</>|Git repository]] has this file:</translate> scripts/watchlist.py |
File:Pywikibot MW gear icon.svg |
<translate> Pywikibot scripts</translate> |
---|
|
· <span style="" title="<translate nowrap> Edit this template</translate>"><translate> e</translate> |
watchlist.py merely outputs the watchlist of the account running the script.
Syntax
Syntax is straightforward, as there appear to be no arguments which can be used with it. Just type python pwb.py watchlist
Usage
From a command line this displays the currently logged in account's watchlist as a list of page titles, and updates the local cache of the watchlist used by other pywikibot modules.
When calling from other programmes, useful functions within this module include refresh() (refreshing the local copy of the watchlist, normally only done monthly) and isWatched() (returning True or False) with Page.watch() and Page.unwatch().
For example the following Python code will unwatch any matching currently watched image on Commons category "Flowers":
import pywikibot
from pywikibot import pagegenerators
from scripts.watchlist import isWatched
site = pywikibot.Site('commons')
cat = pywikibot.Category(site, 'Flowers')
gen = pagegenerators.CategorizedPageGenerator(cat)
for page in gen:
title=page.title()
if isWatched(title, site):
print('Unwatching', title)
page.unwatch()