|
|
@ -1,7 +1,8 @@ |
|
|
|
#!/usr/bin/python3 |
|
|
|
|
|
|
|
import localconf |
|
|
|
import requests |
|
|
|
import pypdftk |
|
|
|
import pygraphviz |
|
|
|
import subprocess |
|
|
|
from requests.auth import HTTPBasicAuth |
|
|
|
import re |
|
|
@ -9,9 +10,9 @@ import os |
|
|
|
import sys |
|
|
|
|
|
|
|
# todo move this variable outta here.. |
|
|
|
|
|
|
|
NODE = '/home/friend/.nvm/versions/node/v16.13.0/bin/node' |
|
|
|
PAGEDJSCLI = '/home/friend/.nvm/versions/node/v16.13.0/bin/pagedjs-cli' |
|
|
|
NODE = localconf.NODE |
|
|
|
PAGEDJSCLI = localconf.PAGEDJSCLI |
|
|
|
BASECSS = 'https://hub.vvvvvvaria.org/rosa/pad/p/design-trial_2.css/export/txt' |
|
|
|
|
|
|
|
localhost = '/var/www/html/pdfs/' |
|
|
|
localurl = 'http://localhost/pdfs/' |
|
|
@ -27,15 +28,18 @@ e2hprocessor='http://totalism.org:7777/glia2?sourceMethod=post&sinkFormat=text/g |
|
|
|
chapters=[] |
|
|
|
outputs=[] |
|
|
|
counter=0 |
|
|
|
ooooo_insert='' |
|
|
|
ooooo_graphs="https://pad.constantvzw.org/p/atnofs-insert" |
|
|
|
|
|
|
|
indexmd = requests.get('https://pad.vvvvvvaria.org/atnofs-index.md/export/txt').text |
|
|
|
|
|
|
|
# download the index of all contributions |
|
|
|
|
|
|
|
with open('index.md','w') as file: |
|
|
|
file.write(indexmd) |
|
|
|
|
|
|
|
basecssget = requests.get(BASECSS).text |
|
|
|
with open(localhost+'base.css','w') as file: |
|
|
|
file.write(basecssget) |
|
|
|
# download the base css style |
|
|
|
|
|
|
|
|
|
|
|
with open('index.md') as file: |
|
|
|
for line in file: |
|
|
@ -51,6 +55,19 @@ with open('index.md') as file: |
|
|
|
if 'ooooo' in line: |
|
|
|
ooooo_insert=line.split('(')[1].split(')')[-2] |
|
|
|
|
|
|
|
oooooc=0 |
|
|
|
if ooooo_insert: |
|
|
|
all_graphs = requests.get(ooooo_graphs+'/export/txt') |
|
|
|
graphs=all_graphs.text.split('[graph]"""') |
|
|
|
for graph in graphs[1:]: |
|
|
|
graph=graph.split('"""')[-2] |
|
|
|
dot = requests.post(e2hprocessor,graph.encode('utf-8')) |
|
|
|
with open('dot/'+str(oooooc)+'.dot','w') as file: |
|
|
|
file.write(dot.text) |
|
|
|
graph = pygraphviz.AGraph('dot/'+str(oooooc)+'.dot') |
|
|
|
graph.layout(prog="dot") |
|
|
|
graph.draw('dot/'+str(oooooc)+'.svg') |
|
|
|
oooooc+=1 |
|
|
|
|
|
|
|
#then iterates over all chapters to get the pdf versions |
|
|
|
for chapter in chapters: |
|
|
@ -68,7 +85,7 @@ for chapter in chapters: |
|
|
|
else: |
|
|
|
preview = requests.get(chapter.replace('pad/','preview.html')) |
|
|
|
style = requests.get(chapter.replace('pad/','stylesheet.css')) |
|
|
|
|
|
|
|
|
|
|
|
stylefile=localhost+name+'/stylesheet.css' |
|
|
|
with open(stylefile, 'w') as file: |
|
|
|
file.write(style.text) |
|
|
@ -83,7 +100,7 @@ for chapter in chapters: |
|
|
|
with open(previewfile, "r") as f: |
|
|
|
contents = f.readlines() |
|
|
|
|
|
|
|
contents.insert(5, '<link href="stylesheet.css" rel="stylesheet" type="text/css" media="screen">') |
|
|
|
contents.insert(5, '<link href="stylesheet.css" rel="stylesheet" type="text/css"><link href="../base.css" rel="stylesheet" type="text/css">') |
|
|
|
|
|
|
|
with open(previewfile, "w") as f: |
|
|
|
contents = "".join(contents) |
|
|
@ -91,24 +108,18 @@ for chapter in chapters: |
|
|
|
# end hack |
|
|
|
|
|
|
|
# this is the pagedjs client version making the pdf out of the localhost version of the html |
|
|
|
subprocess.run([NODE, PAGEDJSCLI, localpreview, '-o', localhost+pdffile]) |
|
|
|
subprocess.run([NODE, PAGEDJSCLI,'--browserArgs','--font-render-hinting=none',localpreview, '-o', localhost+pdffile]) |
|
|
|
|
|
|
|
else: |
|
|
|
if('octomode.vvvvvvaria.org' in chapter): |
|
|
|
chapter=chapter.replace('://','://'+authu+':'+authp+'@') |
|
|
|
preview = chapter.replace('pad/','pagedjs.html') |
|
|
|
subprocess.run([NODE, PAGEDJSCLI, preview, '-o', localhost+pdffile]) |
|
|
|
subprocess.run([NODE, PAGEDJSCLI,'--browserArgs','--font-render-hinting=none', preview, '-o', localhost+pdffile]) |
|
|
|
|
|
|
|
outputs.append(localhost+pdffile) |
|
|
|
|
|
|
|
counter+=1 |
|
|
|
|
|
|
|
if ooooo_insert: |
|
|
|
all_graphs = requests.get(ooooo_insert+'/export/txt') |
|
|
|
graphs=all_graphs.text.split('[graph]"""') |
|
|
|
print(len(graphs)) |
|
|
|
|
|
|
|
|
|
|
|
# compiling all the files in one big pdf! |
|
|
|
|
|
|
|
output = pypdftk.concat(outputs,out_file=localhost+outputname) |
|
|
|