|
|
|
@ -74,7 +74,7 @@ def wiki_title_to_url (wiki, title):
|
|
|
|
|
ret += "/" + p.normalize_title(p.name)
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
def ensure_wiki_image_tiles (wiki, imagepageurl, text='', basepath="tiles", force=False, bgcolor=None, tilewidth=256, tileheight=256, zoom=3):
|
|
|
|
|
def ensure_wiki_image_tiles (wiki, imagepageurl, text='', basepath="tiles", force=False, bgcolor=None, tilewidth=256, tileheight=256, zoom=3, margin_right=0, margin_bottom=0):
|
|
|
|
|
print ("ensure_wiki_image_tiles", imagepageurl, file=sys.stderr)
|
|
|
|
|
page, imageurl = mwfilepage_to_url(wiki, imagepageurl)
|
|
|
|
|
path = os.path.join(basepath, url_to_path(imageurl))
|
|
|
|
@ -89,7 +89,7 @@ def ensure_wiki_image_tiles (wiki, imagepageurl, text='', basepath="tiles", forc
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
im = Image.open(urlopen(imageurl))
|
|
|
|
|
tile_image(im, zoom, tilewidth, tileheight, path+"/", ret.tilename, bgcolor)
|
|
|
|
|
tile_image(im, zoom, tilewidth, tileheight, path+"/", ret.tilename, bgcolor, margin_right, margin_bottom)
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
def textcell (paras):
|
|
|
|
@ -104,7 +104,7 @@ def name_to_path (name):
|
|
|
|
|
return name.replace("/", "_")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_article (wiki, ref, basepath="tiles", depth=0, maxdepth=3):
|
|
|
|
|
def render_article (wiki, ref, basepath="tiles", depth=0, maxdepth=3, tilewidth=256, tileheight=256):
|
|
|
|
|
print ("render_article", ref, file=sys.stderr)
|
|
|
|
|
if type(ref) == Page:
|
|
|
|
|
page = ref
|
|
|
|
@ -150,7 +150,7 @@ def render_article (wiki, ref, basepath="tiles", depth=0, maxdepth=3):
|
|
|
|
|
# article = wiki_absurl(wiki, article)
|
|
|
|
|
# images.append(render_article(wiki, article, caption, basepath, depth+1, maxdepth))
|
|
|
|
|
# else:
|
|
|
|
|
images.append(ensure_wiki_image_tiles(wiki, src, caption, basepath).zoom())
|
|
|
|
|
images.append(ensure_wiki_image_tiles(wiki, src, caption, basepath, tilewidth=tilewidth, tileheight=tileheight).zoom())
|
|
|
|
|
|
|
|
|
|
for a in body.findall('.//a[@class="image"]'):
|
|
|
|
|
caption = a.attrib.get("title", '')
|
|
|
|
@ -162,7 +162,7 @@ def render_article (wiki, ref, basepath="tiles", depth=0, maxdepth=3):
|
|
|
|
|
if src in imgsrcs:
|
|
|
|
|
continue
|
|
|
|
|
imgsrcs[src] = True
|
|
|
|
|
images.append(ensure_wiki_image_tiles(wiki, src, caption, basepath).zoom())
|
|
|
|
|
images.append(ensure_wiki_image_tiles(wiki, src, caption, basepath, tilewidth=tilewidth, tileheight=tileheight).zoom())
|
|
|
|
|
|
|
|
|
|
print ("{0} paras, {1} images".format(len(paras), len(images)), file=sys.stderr)
|
|
|
|
|
|
|
|
|
@ -179,7 +179,7 @@ def render_article (wiki, ref, basepath="tiles", depth=0, maxdepth=3):
|
|
|
|
|
cells.append(textcell(paras))
|
|
|
|
|
cells.extend(images)
|
|
|
|
|
|
|
|
|
|
ret = recursiverender(cells, basename)
|
|
|
|
|
ret = recursiverender(cells, basename, tilewidth=tilewidth, tileheight=tileheight)
|
|
|
|
|
ret['text'] = u"""<p class="caption"><span class="text">{0}</span><a class="url" href="{1}">WIKI</a></p>""".format(title, ref)
|
|
|
|
|
if images:
|
|
|
|
|
ret['image'] = images[0]['image']
|
|
|
|
@ -200,7 +200,7 @@ def render_article (wiki, ref, basepath="tiles", depth=0, maxdepth=3):
|
|
|
|
|
# children.append(gridrender(restimages, basename))
|
|
|
|
|
# return article
|
|
|
|
|
|
|
|
|
|
def render_category (wiki, cat, output="tiles"):
|
|
|
|
|
def render_category (wiki, cat, output="tiles", tilewidth=256, tileheight=256):
|
|
|
|
|
print ("Render Category", cat, file=sys.stderr)
|
|
|
|
|
# if type(cat) == Page:
|
|
|
|
|
# page = ref
|
|
|
|
@ -218,10 +218,10 @@ def render_category (wiki, cat, output="tiles"):
|
|
|
|
|
for m in cat.members():
|
|
|
|
|
pages.append(m)
|
|
|
|
|
pages.sort(key=lambda x: x.name)
|
|
|
|
|
pagenodes = [render_article(wiki, x.name) for x in pages]
|
|
|
|
|
pagenodes = [render_article(wiki, x.name, tilewidth=tilewidth, tileheight=tileheight) for x in pages]
|
|
|
|
|
for page, node in zip(pages, pagenodes):
|
|
|
|
|
node['text'] = u"""<p class="caption"><span class="text">{0}</span><a class="url" href="{1}">WIKI</a></p>""".format(page.name, wiki_title_to_url(wiki, page.name))
|
|
|
|
|
ret = gridrender(pagenodes, output+"/"+cat.name.replace(":", "_"))
|
|
|
|
|
ret = gridrender(pagenodes, output+"/"+cat.name.replace(":", "_"), tilewidth=tilewidth, tileheight=tileheight)
|
|
|
|
|
ret['text'] = u"""<p class="caption"><a class="url" href="{0}">{1}</a></p>""".format(wiki_title_to_url(wiki, cat.name), cat.name)
|
|
|
|
|
return ret
|
|
|
|
|
# for p in pages:
|
|
|
|
@ -238,7 +238,7 @@ def make_category (args):
|
|
|
|
|
|
|
|
|
|
def make_article (args):
|
|
|
|
|
wiki = Site((args.wikiprotocol, args.wikihost), path=args.wikipath)
|
|
|
|
|
root_node = render_article(wiki, args.wikipage)
|
|
|
|
|
root_node = render_article(wiki, args.wikipage, tilewidth=args.tilewidth, tileheight=args.tileheight)
|
|
|
|
|
if args.html:
|
|
|
|
|
print (html(root_node, ""))
|
|
|
|
|
else:
|
|
|
|
@ -248,7 +248,7 @@ def make_gallery(args):
|
|
|
|
|
wiki = Site((args.wikiprotocol, args.wikihost), path=args.wikipath)
|
|
|
|
|
# apiurl = args.wikiprotocol+"://"+args.wikihost+args.wikipath+"api.php"
|
|
|
|
|
if len(args.wikipage) == 1:
|
|
|
|
|
root_node = render_article(wiki, args.wikipage[0])
|
|
|
|
|
root_node = render_article(wiki, args.wikipage[0], tilewidth=args.tilewidth, tileheight=args.tileheight)
|
|
|
|
|
else:
|
|
|
|
|
children = []
|
|
|
|
|
for wikipage in args.wikipage:
|
|
|
|
@ -257,12 +257,12 @@ def make_gallery(args):
|
|
|
|
|
print ("rendering", wikipage, file=sys.stderr)
|
|
|
|
|
cnode = render_category(wiki, wikipage, args.output)
|
|
|
|
|
else:
|
|
|
|
|
cnode = render_article(wiki, wikipage)
|
|
|
|
|
cnode = render_article(wiki, wikipage, tilewidth=args.tilewidth, tileheight=args.tileheight)
|
|
|
|
|
children.append(cnode)
|
|
|
|
|
if args.recursive:
|
|
|
|
|
root_node = recursiverender(children, args.output+"/"+args.name, direction=1)
|
|
|
|
|
root_node = recursiverender(children, args.output+"/"+args.name, direction=1, tilewidth=args.tilewidth, tileheight=args.tileheight)
|
|
|
|
|
else:
|
|
|
|
|
root_node = gridrender(children, args.output+"/"+args.name, direction=1)
|
|
|
|
|
root_node = gridrender(children, args.output+"/"+args.name, direction=1, tilewidth=args.tilewidth, tileheight=args.tileheight)
|
|
|
|
|
|
|
|
|
|
if args.html:
|
|
|
|
|
print (html(root_node, ""))
|
|
|
|
@ -273,6 +273,7 @@ def make_gallery(args):
|
|
|
|
|
def testwiki (args):
|
|
|
|
|
return Site((args.wikiprotocol, args.wikihost), path=args.wikipath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
ap = ArgumentParser("")
|
|
|
|
|