Manual:Pywikibot/Vytvorte si vlastný skript

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:Pywikibot/Create your own script and the translation is 46% complete.
Other languages:
Bân-lâm-gú • ‎Deutsch • ‎English • ‎català • ‎español • ‎français • ‎italiano • ‎português do Brasil • ‎slovenčina • ‎svenska • ‎български • ‎русский • ‎українська • ‎العربية • ‎中文 • ‎日本語 • ‎한국어

Táto stránka má zoznam nejakých veľmi základných tipov na začatie písania vlastného bota. Nezabudnite to písať v user-config.py súbory!

Môžete použiť následujúce príkazy do skrýše(shell), alebo v skripte

Na otvorenie skrýše, zapnitepython pwb.py shell

Ak chcete vytvoriť skrit, prosím, uložte ho v myscript.py v scripts/userscripts/, a potom zapnite python pwb.pymyscript

  • To gain access to the pywikibot library from your Python script, use:
import pywikibot
  • to retrieve a page, use the following, where pageName is the title of the page you would like to retrieve (e.g., Wikipedia:Bots or India):
site = pywikibot.Site()
page = pywikibot.Page(site, u"pageName")
text = page.text
  • to update a page, use:
page.text = u"newText"
page.save(u"Edit comment")
  • look at some of the pywikibot files for other ideas -- scripts/basic.py is relatively easy to read even if you're new to pywikibot.
  • you can find all available Page methods in the pywikibot/page.py file.
  • basic.py gives you a setup that can be used for many different bots, all you have to do is define the string editing on the page text.
import pywikibot
from pywikibot import pagegenerators
site = pywikibot.Site()
cat = pywikibot.Category(site,'Category:Living people')
gen = pagegenerators.CategorizedPageGenerator(cat)
for page in gen:
    #Do something with the page object, for example:
    text = page.text

Pozri tiež


If you need more help on setting up your Pywikibot visit the #pywikibot IRC channel connect or pywikibot@ mailing list.