Pywikipediabot: Difference between revisions

wikademia>Millosh
wikademia>Millosh
Line 193: Line 193:


=== Writing simple "Hello, world!" in PWB ===
=== Writing simple "Hello, world!" in PWB ===
So, let's try to make a page "Hello, world!" with content "Hello, world!" inside of bot's name space.
<source lang="python">
mynick = "My Bot Name"
hello_world = "Hello, world!"
myuserpage = "User:" + mynick
mypage = myuserpage + "/" + hello_world
site = getSite(language,family)
page = Page(site,mypage)
page.put(hello_world)
</source>
And here is the full script:
<source lang="python">
#!/usr/bin/python
# -*- coding: utf-8 -*-
# let's declare all global values here
mydir = "./"
pwbdir = mydir + "pywikipedia/"
language = "en"
family = "wikinews"
mynick = "My Bot Name"
hello_world = "Hello, world!"
myuserpage = "User:" + mynick
mypage = myuserpage + "/" + hello_world
# importing modules
import sys
sys.path.append(pwbdir)
from wikipedia import *
# doing the job
site = getSite(language,family)
page = Page(site,mypage)
page.put(hello_world)
</source>
== Practice ==
# Open accounts for you and bot on all Wikimedia projects. Note that it is a long process and if you don't want to spend 30 hours at once, you will need a month of work. As a starting point, use [http://www.wikimedia.org/ www.wikimedia.org] and pages on [[meta:|Meta]] which are in the form "List of <projectname>s" (like [[meta:List of Wikipedias|List of Wikipedias]]).
# ...


[[Category:Python]]
[[Category:Python]]
[[Category:MediaWiki]]
[[Category:MediaWiki]]
[[Category:Computer programming]]
[[Category:Computer programming]]