0

I am trying to create a page in https://dev.wikidebates.org/wiki/Wikidébats:Accueil, it is similar ti wikipedia, so Pywikibot should work the same way. I would like to make a page using Pywikibot. I checked option scripts in Pywikibot https://www.mediawiki.org/wiki/Manual:Pywikibot/Scripts. The script pagefromfile.py is responsible for it. However, I don't see in the code where I should write link on new page of wiki. Also function inter in class Pagefromfile returns page. How can I check that the page was made?

The code which I try now is the following. Everything works ok, except last line.(Page is not created)

site = pywikibot.Site('dev', 'wikidebates')  # The site we want to run our bot on
page = pywikibot.Page(site, "Faut-il légaliser le cannabis ?")
text = page.get() #get the code of the page

wb = open("pages1.txt", "w", encoding="utf-8") 
wb.write(str(txt)) #write text to the file, in order to download it then to the wiki
wb.close()

main_page('-file:pages1.txt') #use main function from scrip pagefromfile.py - I renamed it

1 Answers1

0

You haven't shown any further information. Probably there are any further messages from pagefromfile.py script. If you download the text from a wiki you either have to include begin and end markers to the text or you have to use the -textonly option. I also propose to use the -title option.

Refer the doc: https://doc.wikimedia.org/pywikibot/stable/scripts/general.html#module-scripts.pagefromfile

from scripts.pagefromfile import main  # or main_page in your modified case
site = pywikibot.Site('wikidebates:dev')  # you may use te site name for the constructor function
page = pywikibot.Page(site, 'Faut-il légaliser le cannabis ?')
text = page.text

with open("pages1.txt", "w", encoding="utf-8") as wp:  # also closes the file
    wb.write(text)

main('-file:pages1.txt', '-textonly', '-title:"The new title"')

To specify the target site, add a -site option to the main function if it is not your default site. For simulating purpose you can use the -simulate option:

main('-file:pages1.txt', '-textonly', '-title:"The new title"', '-simulate', '-site:wikidebates:dev')

Note: all arguments given to the main function must be strings delimited by comma. You cannot give all arguments as a long string except you do it like this:

main(*'-file:pages1.txt -textonly -title:The_new_title'.split())
xqt
  • 280
  • 1
  • 11