site_graphlogo
  -   Terms of Use and Privacy
Source Code
site_graphlogo
  -   Terms of Use and Privacy
Source Code

Source Code | article tag GRa(F) generation

This program runs while editing a domain.

#!/usr/bin/python3
#article tag GRa(F) generation
#Copyright (C) 2020 Tributary Software

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#or view the license here: https://tributarysoftware.com/gpl2.txt
import re
import os
import sys
import time
import codecs
import pprint
import collections
diaghead='digraph {\ncharset=\"utf-8\";'
diaghead+='overlap=\"false\";\n'
diaghead+='splines=\"true\";\n'
diaghead+='sep=\"+5\";\n'
hd=''
out='/home/knoppix/websites/site/'+sys.argv[1]+'/graph/'
os.makedirs(out,exist_ok=True)
rootdocument='/home/knoppix/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('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"','<div id="container" style="width: 100%; height: 95vh;">')
rawsvg=rawsvg.replace('"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">','')
rawsvg=rawsvg.replace('<?xml version="1.0" encoding="UTF-8" standalone="no"?>','')
rawsvg=re.sub('<svg width=".+pt" height=".+"','<svg id="Graph" xmlns="http://www.w3.org/2000/svg"',rawsvg)
rawsvg=re.sub(' viewBox=".+" xmlns','style="display: inline; width: inherit; min-width: inherit; max-width: inherit; height: inherit; min-height: inherit; max-height: inherit; " viewBox="0 0 900 900" version="1.1" xmlms',rawsvg)
rawsvg=rawsvg.replace(' xmlms:xlink="http://www.w3.org/1999/xlink">','>')
fff.close
f = codecs.open(out+'index.html', mode='w', encoding='utf-8')
tp='<!doctype html> <html lang="en"> <head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"><link rel="stylesheet" type="text/css" href="/css/style.css" /><script src="/live.js"></script><title>dfd</title>\n<script src="/svg-pan-zoom.js"></script>\n</head>\n<body><div class="parent"></div>'
js='''  </div><script>
      window.onload = function() {
        window.zoomGraph = svgPanZoom('#Graph', {
          zoomEnabled: true,
          controlIconsEnabled: false,
          fit: true,
          center: true,
        });
      };
    </script>'''
f.write(tp+rawsvg+js+'</body></html>')
f.close

raw source