From 73d4df942a9d1ac6ea81bb663ca66d4bdee5bb92 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Sun, 2 Feb 2020 16:26:03 +0100 Subject: [PATCH] sandbox: wiki_images.py --- .gitignore | 1 + download_imgs.py | 8 ++------ sandbox/wiki_images.py | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 sandbox/wiki_images.py diff --git a/.gitignore b/.gitignore index 6ec89a9..ee6496f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ lib/ lib64 pyvenv.cfg share/ +images.json diff --git a/download_imgs.py b/download_imgs.py index 712c75b..34c1e0c 100644 --- a/download_imgs.py +++ b/download_imgs.py @@ -1,12 +1,10 @@ -import os, json - +import os from mwclient import Site from pprint import pprint - from functions import update_json site = Site(host='hub.xpub.nl/sandbox', path='/itchwiki/') -wd = os.path.abspath('.') # working directory +wd = os.path.dirname(os.path.abspath(__file__)) # working directory imgdir = os.path.join(wd, 'images') os.makedirs(imgdir, exist_ok=True) # create images/ dir @@ -18,8 +16,6 @@ imgsjson_fn = os.path.join(wd, 'images.json') with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd loginlines = login.read() user, pwd = loginlines.split('\n') - user.replace('\n', '') - pwd.replace('\n', '') site.login(username=user, password=pwd) # login to wiki print(site) diff --git a/sandbox/wiki_images.py b/sandbox/wiki_images.py new file mode 100644 index 0000000..630784b --- /dev/null +++ b/sandbox/wiki_images.py @@ -0,0 +1,24 @@ +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')