#!/usr/bin/python3 # coding=utf-8 #article tag GRa(F) generation # The person who associated a work with this deed has dedicated # the work to the public domain by waiving all of his or her rights # to the work worldwide under copyright law, including all related # and neighboring rights, to the extent allowed by law. # You can copy, modify, distribute and perform the work, even for # commercial purposes, all without asking permission. # In no way are the patent or trademark rights of any person affected by # CC0, nor are the rights that other persons may have in the work or in # how the work is used, such as publicity or privacy rights. # Unless expressly stated otherwise, the person who associated a work with # this deed makes no warranties about the work, and disclaims liability # for all uses of the work, to the fullest extent permitted by applicable law. # When using or citing the work, you should not imply endorsement by the # author or the affirmer. # https://creativecommons.org/publicdomain/zero/1.0/ import re import os import sys import time import codecs import pprint import collections from pathlib import Path diaghead='digraph {\ncharset=\"utf-8\";' diaghead+='overlap=\"false\";\n' diaghead+='splines=\"true\";\n' diaghead+='sep=\"+5\";\n' home = str(Path.home())+'/sync' hd='' out=home+'/websites/site/'+sys.argv[1]+'/graph/' os.makedirs(out,exist_ok=True) rootdocument=home+'/websites/source/'+sys.argv[1]+'/' version='' graph=[] label={} for root,dirs,files in os.walk(rootdocument, followlinks=False): for fname in files: if not fname.startswith('.') and fname.find('^^')==-1: p=os.path.join(root,fname) bits=re.compile(re.escape(rootdocument+'0/')+r'(.+)/(\d+)/(has_tag)/(.+)') m = bits.match(p) try: subject=m.group(2) predicate=m.group(3) objct=m.group(4)[:-3] with open(rootdocument+'0/'+m.group(1)+'/'+subject+'.title.txt') as fl: l=fl.read().rstrip().replace('"','\'') graph.append('"'+m.group(1).replace('/','~')+'~'+subject+'" -> "tags~'+objct+'"') label[m.group(1).replace('/','~')+'~'+subject]=l label['tags~'+objct]=objct except: six=9 alll='' pprint.pprint(label) for line in label: alll+='"'+line+'" [href="/'+line.replace('~','/')+'/" label="'+label[line]+'"]\n' for line in graph: alll+=line+'\n' with open(out+'graph.gv', 'w+') as fa: fa.write(diaghead+alll+'}'+'\n') os.system("sfdp -Tsvg '"+out+"graph.gv' -o '"+out+"graph.svg'") fff = codecs.open(out+'graph.svg', mode='r', encoding='utf-8') rawsvg=fff.read().replace('') rawsvg=rawsvg.replace('"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">','') rawsvg=rawsvg.replace('','') rawsvg=re.sub('','>') fff.close f = codecs.open(out+'index.html', mode='w', encoding='utf-8') tp=' dfd\n\n\n
' js=''' ''' f.write(tp+rawsvg+js+'') f.close