From 363254fa331cfb8127213a36ce7fe62654ac372f Mon Sep 17 00:00:00 2001 From: Castro0o Date: Sun, 2 Feb 2020 14:54:44 +0100 Subject: [PATCH] images being downloaded --- .gitignore | 10 ++++++++++ README.md | 25 +++++++++++++++++++++++++ download_imgs.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 download_imgs.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ec89a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +login.txt +images/ + +# venv dirs & files +.idea/ +bin/ +lib/ +lib64 +pyvenv.cfg +share/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..aea5422 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Wiki to HTML pages script + +## Depencencies +* python3 +* [pip]() Python library installed + * Install: + * `curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py` + * `python3 get-pip.py` + +* [mwclient](https://mwclient.readthedocs.io/en/latest/index.html) Python library + * Install: + * `pip3 install mwclient` + +## login.txt +`login.txt` is a secrete file (ignored by git) where you place you itch wiki username and password, in separate lines. + +It is used to let mwclient access the wiki, since it is close for reading and writing. +``` +myusername +mypassword +``` + + +## Run +* `python3 download_imgs.py` \ No newline at end of file diff --git a/download_imgs.py b/download_imgs.py new file mode 100644 index 0000000..306d9e2 --- /dev/null +++ b/download_imgs.py @@ -0,0 +1,36 @@ +import os + +from mwclient import Site +from pprint import pprint + +site = Site(host='hub.xpub.nl/sandbox', path='/itchwiki/') +wd = os.path.abspath('.') # working directory + +imgdir = os.path.join(wd, 'images') +os.makedirs(imgdir, 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') + user.replace('\n', '') + pwd.replace('\n', '') + site.login(username=user, password=pwd) # login to wiki + +print(site) + +for n , img in enumerate(site.allimages()): + if n < 3: + print(img) + # print(img.__dict__) # info contained in each img object + # important img info to dictionary + img_dict = { + 'name': img.name, + 'filename': img.page_title, + 'timestamp': img.imageinfo['timestamp'], + 'url': img.imageinfo['url'], + 'urldesc': img.imageinfo['descriptionshorturl'], + } + pprint(img_dict) + img_fn = os.path.join(imgdir, img_dict['filename']) + with open(img_fn, 'wb') as img_file: + img.download(destination=img_file)