You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
842 B
Python

import os
from dotenv import load_dotenv
from pathlib import Path
# load the .env variables, they will be accessible from os.environ
# /var/www is the path for the shared folder of the Soupboat
# (not accessible from the outside web)
dotenv_path = Path("/var/www/.mw-credentials")
load_dotenv(dotenv_path=dotenv_path)
# use the variable without revealing them
site = mwclient.Site('pzwiki.wdka.nl', path='/mw-mediadesign/')
site.login(
username=os.environ.get('MW_BOT'),
password=os.environ.get('MW_KEY')
)
# ... etc etc etc do your things
# 2. Get a page to edit. If it doesn't exist it will be created
page = site.pages['A test page']
# 3. Get the text from the page
text = page.text()
# 4. Edit the contents
text += 'Editing the test page from the wiki'
# 5. Write the modification
page.edit(text, 'Summary of the edit')