pypyp
This commit is contained in:
parent
2b81ecc004
commit
bc774cadb5
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
localconf.py
|
||||||
|
|
4
localconf.py
Normal file
4
localconf.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
NODE = '/home/dickreckard/.nvm/versions/node/v16.18.1/bin/node'
|
||||||
|
PAGEDJSCLI = '/home/dickreckard/.nvm/versions/node/v16.18.1/bin/pagedjs-cli'
|
5
localconf.pyexample
Normal file
5
localconf.pyexample
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
NODE = '/home/friend/.nvm/versions/node/v16.13.0/bin/node'
|
||||||
|
PAGEDJSCLI = '/home/friend/.nvm/versions/node/v16.13.0/bin/pagedjs-cli'
|
||||||
|
|
@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
import localconf
|
||||||
import requests
|
import requests
|
||||||
import pypdftk
|
import pypdftk
|
||||||
|
import pygraphviz
|
||||||
import subprocess
|
import subprocess
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
import re
|
import re
|
||||||
@ -9,9 +10,9 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
# todo move this variable outta here..
|
# todo move this variable outta here..
|
||||||
|
NODE = localconf.NODE
|
||||||
NODE = '/home/friend/.nvm/versions/node/v16.13.0/bin/node'
|
PAGEDJSCLI = localconf.PAGEDJSCLI
|
||||||
PAGEDJSCLI = '/home/friend/.nvm/versions/node/v16.13.0/bin/pagedjs-cli'
|
BASECSS = 'https://hub.vvvvvvaria.org/rosa/pad/p/design-trial_2.css/export/txt'
|
||||||
|
|
||||||
localhost = '/var/www/html/pdfs/'
|
localhost = '/var/www/html/pdfs/'
|
||||||
localurl = 'http://localhost/pdfs/'
|
localurl = 'http://localhost/pdfs/'
|
||||||
@ -27,15 +28,18 @@ e2hprocessor='http://totalism.org:7777/glia2?sourceMethod=post&sinkFormat=text/g
|
|||||||
chapters=[]
|
chapters=[]
|
||||||
outputs=[]
|
outputs=[]
|
||||||
counter=0
|
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
|
indexmd = requests.get('https://pad.vvvvvvaria.org/atnofs-index.md/export/txt').text
|
||||||
|
|
||||||
# download the index of all contributions
|
# download the index of all contributions
|
||||||
|
|
||||||
with open('index.md','w') as file:
|
with open('index.md','w') as file:
|
||||||
file.write(indexmd)
|
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:
|
with open('index.md') as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
@ -51,6 +55,19 @@ with open('index.md') as file:
|
|||||||
if 'ooooo' in line:
|
if 'ooooo' in line:
|
||||||
ooooo_insert=line.split('(')[1].split(')')[-2]
|
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
|
#then iterates over all chapters to get the pdf versions
|
||||||
for chapter in chapters:
|
for chapter in chapters:
|
||||||
@ -68,7 +85,7 @@ for chapter in chapters:
|
|||||||
else:
|
else:
|
||||||
preview = requests.get(chapter.replace('pad/','preview.html'))
|
preview = requests.get(chapter.replace('pad/','preview.html'))
|
||||||
style = requests.get(chapter.replace('pad/','stylesheet.css'))
|
style = requests.get(chapter.replace('pad/','stylesheet.css'))
|
||||||
|
|
||||||
stylefile=localhost+name+'/stylesheet.css'
|
stylefile=localhost+name+'/stylesheet.css'
|
||||||
with open(stylefile, 'w') as file:
|
with open(stylefile, 'w') as file:
|
||||||
file.write(style.text)
|
file.write(style.text)
|
||||||
@ -83,7 +100,7 @@ for chapter in chapters:
|
|||||||
with open(previewfile, "r") as f:
|
with open(previewfile, "r") as f:
|
||||||
contents = f.readlines()
|
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:
|
with open(previewfile, "w") as f:
|
||||||
contents = "".join(contents)
|
contents = "".join(contents)
|
||||||
@ -91,24 +108,18 @@ for chapter in chapters:
|
|||||||
# end hack
|
# end hack
|
||||||
|
|
||||||
# this is the pagedjs client version making the pdf out of the localhost version of the html
|
# 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:
|
else:
|
||||||
if('octomode.vvvvvvaria.org' in chapter):
|
if('octomode.vvvvvvaria.org' in chapter):
|
||||||
chapter=chapter.replace('://','://'+authu+':'+authp+'@')
|
chapter=chapter.replace('://','://'+authu+':'+authp+'@')
|
||||||
preview = chapter.replace('pad/','pagedjs.html')
|
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)
|
outputs.append(localhost+pdffile)
|
||||||
|
|
||||||
counter+=1
|
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!
|
# compiling all the files in one big pdf!
|
||||||
|
|
||||||
output = pypdftk.concat(outputs,out_file=localhost+outputname)
|
output = pypdftk.concat(outputs,out_file=localhost+outputname)
|
||||||
|
Loading…
Reference in New Issue
Block a user