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/sandbox/wiki_images.py

25 lines
872 B
Python

import os
from mwclient import Site
from pprint import pprint
site = Site(host='hub.xpub.nl/sandbox', path='/itchwiki/')
wd = os.path.dirname(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
print(site)
for n, img in enumerate(site.allimages()):
if n < 5:
print(img)
print('Image attributes:')
pprint(img.__dict__) # info contained in each img object
print('Image object methods:', dir(img))
# important img info to dictionary
print(img.name, img.page_title, img.imageinfo['timestamp'], img.imageinfo['url'],
img.imageinfo['descriptionshorturl'])
print('\n')