Browse Source

pushing the scripts to generate bricolages

master
mb 2 years ago
commit
4bdefbb5e9
  1. 35
      download-materials.sh
  2. 145
      generate-bricolages.py

35
download-materials.sh

@ -0,0 +1,35 @@
USERNAME=mb
KEY=~/.ssh/varia.pub
mkdir materials
mkdir materials/hold-and-release/
mkdir materials/publishing-partyline/
mkdir materials/plaintext-protocols/
mkdir materials/push-to-talk/
mkdir materials/colonial-infrastructures/
scp -r -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/archive/2022-12-3-4-Colonial_Infrastructures ./materials/colonial-infrastructures/
scp -r -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/archive/2022-12-08-Push-To-Talk-Partyline ./materials/push-to-talk/
scp -r -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/archive/2022-10-publishing-partyline ./materials/publishing-partyline/
scp -r -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/archive/2022-09-17-16-Plaintext-Protocol-Partyline/ ./materials/plaintext-protocols/
scp -r -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/logs/x-y/ ./materials/plaintext-protocols/
scp -r -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/logs/hold-and-release/ ./materials/hold-and-release/
scp -r -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/logs/publishing-partyline/ ./materials/publishing-partyline/
curl https://pad.vvvvvvaria.org/partylines.hold-and-release/export/html > materials/hold-and-release/pad.html
curl https://pad.vvvvvvaria.org/ppp/export/html > materials/plaintext-protocols/pad.html
curl https://pad.vvvvvvaria.org/partylines.publishing-partyline/export/html > materials/publishing-partyline/pad.html
scp -p 12345 $USERNAME@vvvvvvaria.org:/var/www/html/plaintext-protocols-partyline.html ./materials/plaintext-protocols/announcement-nl.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/hold-and-release.html ./materials/hold-and-release/announcement-nl.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/publishing-partyline.html ./materials/publishing-partyline/announcement-nl.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/push-to-talk-partyline.html ./materials/push-to-talk/announcement-nl.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/colonial-infrastructures.html ./materials/colonial-infrastructures/announcement-nl.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/en/plaintext-protocols-partyline.html ./materials/plaintext-protocols/announcement-en.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/en/hold-and-release.html ./materials/hold-and-release/announcement-en.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/en/publishing-partyline.html ./materials/publishing-partyline/announcement-en.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/en/push-to-talk-partyline.html ./materials/push-to-talk/announcement-en.html
scp -P 12345 -i $KEY $USERNAME@vvvvvvaria.org:/var/www/html/en/colonial-infrastructures.html ./materials/colonial-infrastructures/announcement-en.html

145
generate-bricolages.py

@ -0,0 +1,145 @@
import os
from glob import glob
from pprint import pprint
from random import choice
import pypandoc
import base64
# --------------------------------------------------
# Parameters
# number of items on one page
nr_of_items = 10
# number of different pages it will generate for each partyline
nr_of_versions = 10
# you can download the materials with download-materials.sh
materials_folder = "materials"
# this is the folder where the bricolages will be saved to
output_folder = "generated-bricolages"
# for uploading the pages with images somehwere
encode_imgs_as_base64 = True
# --------------------------------------------------
# First make an index of all the files
index = {}
dir = f"./{ materials_folder }/*"
folders = glob(dir, recursive=True)
for folder in folders:
name = folder.replace("./materials/", "")
dir = folder + "/**"
materials = glob(dir, recursive=True)
index[name] = materials
# pprint(index)
# ---------------------------------------------------
# Functions
def parsePad(pad):
"""Parses pad into a list of <p>'s"""
html = open(pad, "r").read()
paragraphs = html.split("<br>")
paragraphs = [p for p in paragraphs if p]
paragraphs = [p for p in paragraphs if not "body>" in p]
paragraphs = [p for p in paragraphs if not "html>" in p]
return paragraphs
def parseAnnouncement(page):
"""Parses an announcement page from the website into a list of <p>'s"""
html = open(page, "r").read()
paragraphs = html.split("\n")
paragraphs = [p for p in paragraphs if p]
paragraphs = [p for p in paragraphs if "<p>" in p]
paragraphs = [p for p in paragraphs if not "body>" in p]
paragraphs = [p for p in paragraphs if not "html>" in p]
paragraphs = [p.replace("\t", "") for p in paragraphs]
return paragraphs
def parseAllItems(partyline):
"""Makes a list of all items of one partyline"""
all_items = []
for item in index[partyline]:
el = ""
for ext in ["jpg","png","jpeg"]:
if item.endswith(ext):
if encode_imgs_as_base64 == True:
img = open(item, "rb").read()
img_in_base64 = base64.b64encode(img)
el = f"<img src='data:image/jpeg;base64,{ img_in_base64.decode('utf-8') }'>"
else:
el = f"<img src='{ item }'>"
all_items.append(el)
if "pad.html" in item:
paragraphs = parsePad(item)
for paragraph in paragraphs:
# do not wrap <ul>'s in <p>'s'
if "<ul" in paragraph:
el = f"<div class='item pad'>{ paragraph }</div>"
else:
el = f"<p class='pad'>{ paragraph }</p>"
all_items.append(el)
if "announcement" in item:
paragraphs = parseAnnouncement(item)
for paragraph in paragraphs:
el = f"<div class='item announcement'>{ paragraph }</div>"
all_items.append(el)
return all_items
def generateHTML(partyline, all_items, x):
"""Generates an HTML page with $nr of items."""
html = ""
for i in range(nr_of_items):
random_choice = choice(all_items) + "\n\n"
# print(random_choice)
# print("------")
html += random_choice
template = f"""<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>{ html }</body>
</html>
"""
# check if output folder exists
if not os.path.exists(output_folder):
os.system(f"mkdir { output_folder }")
out = open(f"{ output_folder }/archive-bricolage-{ partyline }-{ str(x) }.html", "w")
out.write(template)
out.close()
return html
def generateMD(partyline, html, x):
md = pypandoc.convert_text(html, 'md', format='html')
out = open(f"{ output_folder }/archive-bricolage-{ partyline }-{ str(x) }.md", "w")
out.write(md)
out.close()
# ---------------------------------------------------
# Make a list of all items for each partyline that includes:
# - paragraphs from pads
# - images
# - paragraphs from announcement text
#
# Generate a HTML page with $nr of items
# Also save the HTML page as MD file
for x in range(nr_of_versions):
for partyline in index.keys():
all_items = parseAllItems(partyline)
html = generateHTML(partyline, all_items, x)
generateMD(partyline, html, x)
Loading…
Cancel
Save