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.
special-issue-11-wiki2html/populate_title_pages2.py

30 lines
1.0 KiB
Python

import os, argparse, sys, re, json
from mwclient import (Site,
errors)
# login
site = Site(host='hub.xpub.nl/sandbox', path='/itchwiki/')
wd =os.path.dirname(os.path.abspath(__file__)) # parent working directory
with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
loginlines = login.read()
user, pwd = loginlines.split('\n')
site.login(username=user, password=pwd) # login to wiki
# To query a large number of ite:
for i in range(0, 1500, 100):
# variable i will increase 100 at each iteration
# between 0 and 1400
# and will make the offset parameter change
print('\n', f'Querying from {i} to {i+100}', '\n')
ask_query = f'[[Category:Title]]|format=json|limit=100|offset={i}'
response = site.api(action='ask', query=ask_query)
for pagetitle in response['query']['results']:
print(pagetitle)
page = site.pages[pagetitle]
# # text = page.text()
page.save('{{Publication}}\n[[Category:Title]]')