From a22168a50ef1796fc6cf026ee5292e934840498d Mon Sep 17 00:00:00 2001 From: camilo Date: Thu, 5 May 2022 16:05:51 +0200 Subject: [PATCH] python script File --- python.py | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 python.py diff --git a/python.py b/python.py new file mode 100644 index 0000000..c02c619 --- /dev/null +++ b/python.py @@ -0,0 +1,137 @@ +# Libraries + +import json, pypandoc +from urllib.request import urlopen +from urllib.parse import urlencode + +# Connecting via API with the pad + +with open("/opt/etherpad/APIKEY.txt") as f: + api_key = f.read().strip() + +api_url = "https://hub.xpub.nl/soupboat/pad/api/1.2.15/" + +# wrap in a convenient function (APICALL) +def ep (api_fn, api_url, api_key, **data): + data['apikey'] = api_key + return json.load(urlopen(f"{api_url}{api_fn}", data=urlencode(data).encode())) + + +glossary = ep("getText", api_url, api_key, padID="camilo_glossary") + +text = glossary["data"]["text"] + +# Converting markdown text into html + +words = pypandoc.convert_text(text, 'html', format='md') + +# Defining a dictionary of properties + +properties = [ + { + 'title':'action', + 'symbol':'A', + 'color': 'green' + }, + { + 'title':'situation', + 'symbol':'S', + 'color': 'aqua' + }, + { + 'title':'logic', + 'symbol':'L', + 'color': 'orange' + }, +] + +# Writing a legend using the properties + +legend = '' + +i = 0 + +for title, symbol, color in properties: + title = properties[i]['title'] + legend += f'''\n''' + i += 1 + + +# Adding property symbols in front of each word generating a Java script code: + +script = '' + +i = 0 + +for title, symbol, color in properties: + title = properties[i]['title'] + symbol = properties[i]['symbol'] + script += (f"""const {title} = document.getElementsByClassName("{title}"); + for (let i = 0; i < {title}.length; i++)"""'{\n' + f"""{title}[i].innerHTML += "{symbol}";""" + '\n}\n\n') + i += 1 + +# Generating a css style using properties values: + +style = '' + +i = 0 + +for title, symbol, color in properties: + title = properties[i]['title'] + color = properties[i]['color'] + style += f'''.{title}-s''' + '{' + f'''color:{color};''''}' + i += 1 + +# Writing the glossary website +# Note that here you are using the previous variables **style**, **legend**, and **script** + +body = f''' + + + + + + Attempt to Glossary + + + + +
+

Glossary for a Diffractive Publishing Practice

+ +

follow what is new (rss)

+
+
+
+
+

This glossary project is an ongoing and ever-transforming experiment that introduces a diffractive methodology inside the publishing practice. It is seen as a mutable and living publication result of collective workshops where participants are invited to think and converse around its words and annotations. During the workshop, diffraction performs a conscious interconnection of practices beyond reflection. The current state of the glossary gathers different annotations on each word instead of a closed definition for each one.

+

Concretly, the glossary as a publication uses questions as triggers and it aims to weave as a conversation the multiple{description}of the current practice, with other vocabularies that come from critical theory, new materialism and others. The final intention is not just to envision our future as publishers but to help to initiate conversations with others.

+
+
+
+
+
+
+
+ {legend} +
+
+
+ {words} +
+ + + + ''' + +# Writing the `index.html` file + +``` +website = open('index.html','w') + +website.write(body) +website.close()