Wednesday, May 1, 2013

simplemediawiki edit example - python


 # ---------------- python code start ----------------------


from simplemediawiki import MediaWiki

wiki = MediaWiki('http://192.168.20.20/mediawiki/api.php')

myUserName = "xxx"
myPassword = "xxx"


#logs in
loginData = wiki.call({'action':'login', 'lgname': myUserName,'lgpassword': myPassword})

print loginData

#resubmission of the login token
personalLoginData = wiki.call({'action':'login', 'lgname': myUserName ,'lgpassword': myPassword,'lgtoken': loginData['login']['token'$

print "[][][]]"
print personalLoginData
print "[][][][]"
returnData = wiki.call({'action':'query','prop':'info', 'titles':'Main_Page','intoken':'edit'});

print returnData

  # get the edittoken:

edittoken = returnData['query']['pages']['1']['edittoken']
print "----"
print edittoken
print "----"

results = wiki.call({'action':'edit','title':"testwiki1_Page",'section':'new','text':"new page sample text",'token':edittoken})

print results


 # ---------------- python code end ----------------------

No comments: