images being downloaded
commit
363254fa33
@ -0,0 +1,10 @@
|
||||
login.txt
|
||||
images/
|
||||
|
||||
# venv dirs & files
|
||||
.idea/
|
||||
bin/
|
||||
lib/
|
||||
lib64
|
||||
pyvenv.cfg
|
||||
share/
|
@ -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`
|
@ -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)
|
Loading…
Reference in New Issue