sandbox: wiki_images.py

andre
Castro0o 4 years ago
parent ce2d679f10
commit 73d4df942a

1
.gitignore vendored

@ -8,3 +8,4 @@ lib/
lib64
pyvenv.cfg
share/
images.json

@ -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)

@ -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')
Loading…
Cancel
Save