import os, json from mwclient import Site from pprint import pprint from jinja2 import Template from functions import pandoc, page_props, unpack_response site = Site(host='hub.xpub.nl/sandbox', path='/itchwiki/') wd = os.path.dirname(os.path.abspath(__file__)) # working directory imgdir = os.path.join(wd, 'images') imgsjson_fn = os.path.join(wd, 'images.json') with open(imgsjson_fn, 'r') as imgsjson_file: images_info = json.load(imgsjson_file) static_html = os.path.join(wd, 'static_html') os.makedirs(static_html, exist_ok=True) # create images/ dir 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 query = ('[[File:+]][[Title::+]][[Date::+]]|?Title|?Date|?Part|sort=Date,Title,Part|order=asc,asc,asc') print('Query:', query) for answer in site.ask(query): # print(answer, answer.keys()) printout_dict = unpack_response(answer) pprint(printout_dict) img_info = images_info[printout_dict['page']] page = site.pages[[printout_dict['page']]] pagetext = page.text() pagetext_html = pandoc(content=pagetext, format_in='mediawiki', format_out='html') img_local = os.path.join(imgdir, img_info.get('filename')) # pprint(img_info) print(img_local, pagetext_html, '\n') # # # # page_html_template = ''' # # #
# # #