Meta:Tools/Wiki Bots/Python/mwclient/wiki tree graph
< Meta:Tools | Wiki Bots | Python/mwclient
Making a graph of the wiki's structure
So, I've tried to graph this scary monster :) This script below is rather naive and have to be fixed I'm sure, but it let you navigate the structure of the wiki tree, which Campbell has put here blender_wiki_081213.png (BEWARE this is a huge 30MB image, be kind with Blender's servers :)
Please download it only if you are interested, or if you really can't run the script below.
#! /usr/bin/env python
def main():
import mwclient
site = mwclient.Site('wiki.blender.org',path='')
import pydot
bwiki_dot=open('bwiki.dot','w')
graph_header='''digraph graphname{
graph [
fontname = "Helvetica-Oblique",
fontsize = 36,
label = "BlenderWiki",
];
node [
color = white,
style = filled,
fontname = "Helvetica-Outline"
];
'''
bwiki_dot.write(graph_header)
colors={0:'orangered',1:'yellow',2:'greenyellow',3:'goldenrod2',\
4:'dodgerblue1',5:'thistle2',6:'lemonchiffon2'}
print "reading data + building the tree (quick)..."
nodes=[]
links=[]
for page in site.allpages(namespace=0):
if '/' in page.name and not page.redirect:
urlist=page.name.encode('utf-8').split('/')
for index,name in enumerate(urlist):
name='/'.join(urlist[:index+1])
label=urlist[index]
label_line='"%s" [label="%s", color="%s"];\n' % (name,label,colors[index])
if name not in nodes:
bwiki_dot.write(label_line)
nodes.append(name)
if index<len(urlist)-1:
c_name='/'.join(urlist[:index+2])
c_label=urlist[index+1]
label_line='"%s" [label="%s", color="%s"];\n' % (c_name,c_label,colors[index+1])
if c_name not in nodes:
bwiki_dot.write(label_line)
nodes.append(c_name)
if (name,c_name) not in links:
link_line='"%s" -> "%s"\n' % (name,c_name)
bwiki_dot.write(link_line)
links.append((name,c_name))
bwiki_dot.write('}\n')
bwiki_dot.close()
print "creating graph (takes a lot of time)..."
g=pydot.graph_from_dot_file('bwiki.dot')
print "creating image (takes some time)..."
g.write_png('bwiki.png', prog='fdp')
if __name__ == '__main__':
main()
As I wrote above, place this script in a folder as 'bwiki-tree.py', together with the mwclient folder. In the shell, go to the folder that contains bwiki-tree.py and mwclients folder and run python. Then type
exec file('bwiki-tree.py')
or use the complete path to bwiki-tree.py if you have problems.