script to compile the PDFs of the atnofs publication
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.6 KiB

2 years ago
#!/usr/bin/python3
1 year ago
import localconf
2 years ago
import requests
import pypdftk
1 year ago
import pygraphviz
2 years ago
import subprocess
from requests.auth import HTTPBasicAuth
import re
import os
import sys
2 years ago
# todo move this variable outta here..
1 year ago
NODE = localconf.NODE
PAGEDJSCLI = localconf.PAGEDJSCLI
BASECSS = 'https://hub.vvvvvvaria.org/rosa/pad/p/design-trial_2.css/export/txt'
2 years ago
localhost = '/var/www/html/pdfs/'
localurl = 'http://localhost/pdfs/'
2 years ago
outputname='atnofs-compiled.pdf'
authu='octomode'
authp='spider'
authvvvvvv = HTTPBasicAuth('octomode', 'spider')
e2hprocessor='http://totalism.org:7777/glia2?sourceMethod=post&sinkFormat=text/graph/graphviz'
chapters=[]
outputs=[]
counter=0
1 year ago
ooooo_graphs="https://pad.constantvzw.org/p/atnofs-insert"
2 years ago
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)
1 year ago
basecssget = requests.get(BASECSS).text
with open(localhost+'base.css','w') as file:
file.write(basecssget)
# download the base css style
2 years ago
with open('index.md') as file:
for line in file:
# searches for the chapter links
x = re.search ('[.*](.*/pad/)',line)
if x:
line=line.split('(')[1].split(')')[-2]
chapters.append(line)
# searches for ooooo insert
if 'ooooo' in line:
ooooo_insert=line.split('(')[1].split(')')[-2]
1 year ago
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
2 years ago
#then iterates over all chapters to get the pdf versions
for chapter in chapters:
name=str(counter).zfill(2)+'-'+chapter.split('/')[-3]
if not os.path.exists(localhost+name):
os.makedirs(localhost+name)
pdffile=name+'.pdf'
2 years ago
if len(sys.argv)<2 or sys.argv[1]=='nonlocal':
2 years ago
if('octomode.vvvvvvaria.org' in chapter):
preview = requests.get(chapter.replace('pad/','preview.html'), auth=authvvvvvv)
style = requests.get(chapter.replace('pad/','stylesheet.css'), auth=authvvvvvv)
else:
preview = requests.get(chapter.replace('pad/','preview.html'))
style = requests.get(chapter.replace('pad/','stylesheet.css'))
1 year ago
2 years ago
stylefile=localhost+name+'/stylesheet.css'
with open(stylefile, 'w') as file:
file.write(style.text)
previewfile=localhost+name+'/preview.html'
localpreview=localurl+name+'/preview.html'
with open(previewfile, 'w') as file:
file.write(preview.text)
# hacke before octomode is fixed on vvvvaria
with open(previewfile, "r") as f:
contents = f.readlines()
1 year ago
contents.insert(5, '<link href="stylesheet.css" rel="stylesheet" type="text/css"><link href="../base.css" rel="stylesheet" type="text/css">')
2 years ago
with open(previewfile, "w") as f:
contents = "".join(contents)
f.write(contents)
# end hack
# this is the pagedjs client version making the pdf out of the localhost version of the html
1 year ago
subprocess.run([NODE, PAGEDJSCLI,'--browserArgs','--font-render-hinting=none',localpreview, '-o', localhost+pdffile])
2 years ago
else:
if('octomode.vvvvvvaria.org' in chapter):
chapter=chapter.replace('://','://'+authu+':'+authp+'@')
preview = chapter.replace('pad/','pagedjs.html')
1 year ago
subprocess.run([NODE, PAGEDJSCLI,'--browserArgs','--font-render-hinting=none', preview, '-o', localhost+pdffile])
2 years ago
2 years ago
outputs.append(localhost+pdffile)
2 years ago
counter+=1
# compiling all the files in one big pdf!
2 years ago
output = pypdftk.concat(outputs,out_file=localhost+outputname)
2 years ago