commit e9447513bb11d3a0483c88a705f07c756e3b2402
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Sat, 17 Aug 2019 18:49:22 +0200
import old stuff
Diffstat:
8 files changed, 363 insertions(+), 0 deletions(-)
diff --git a/README b/README
@@ -0,0 +1,22 @@
+plint_extra: extra tools for Plint
+Copyright (C) 2011-2019 by Antoine Amarilli
+
+This repository contains extra tools for plint (<https://gitlab.com/a3nm/plint>
+/ <https://plint.a3nm.net/>).
+
+- irc/: IRC frontend (undocumented)
+
+An undocumented IRC interface for use with irctk is available (plint_irc.py).
+
+- poem2html: script to compile poems to HTML
+
+The poems produced by plint_irc.py can be compiled to HTML automatically using
+something along the lines of:
+
+ while true
+ do
+ inotifywait poem_file
+ # www/ should contain style.css
+ poem2html/make_poem.sh poem_file > www/poem.html
+ done
+
diff --git a/irc/filter_irc.py b/irc/filter_irc.py
@@ -0,0 +1,11 @@
+#!/usr/bin/python3 -u
+
+import sys
+
+sys.stdin = sys.stdin.detach()
+while True:
+ l = sys.stdin.readline()
+ if not l:
+ break
+ l = l.decode('utf8').strip()
+ print(''.join((l.split(">"))[1:]))
diff --git a/irc/plint_irc.py b/irc/plint_irc.py
@@ -0,0 +1,138 @@
+#!/usr/bin/python3 -uO
+
+from plint import localization, rhyme, diaeresis
+import re
+import sys
+from plint.template import Template
+from pprint import pprint
+from plint.common import normalize
+
+buf = ""
+lbuf = []
+
+def write(l, descriptor=None):
+ if descriptor:
+ f = descriptor
+ else:
+ f = open(sys.argv[2], 'a')
+ print(' '.join(l), file=f)
+ if not descriptor:
+ f.close()
+
+def output(l, descriptor):
+ print(' '.join(l), file=descriptor)
+ write(l, descriptor if descriptor != sys.stdout else None)
+
+def leading_cap(text):
+ for c in text:
+ if c.upper() == c.lower():
+ continue # symbol
+ if c != c.lower():
+ return True
+ if c != c.upper():
+ return False
+ return False
+
+def manage(line, descriptor=sys.stdout):
+ """manage one line, indicate if an error occurred"""
+ global buf
+ global lbuf
+ usebuf = False
+ l = line.rstrip().split(' ')
+ text = ' '.join(l[1:])
+ if normalize(text.strip()) == '':
+ return True # no text
+ first = [a for a in l[1:] if a != ''][0]
+ if first == '/me' and len(l) >= 3 and l[2] == 'plint':
+ # always accept actions
+ if len(lbuf) > 0:
+ lbuf.append(l)
+ else:
+ write(l, descriptor)
+ return True
+ if first[0] == '/':
+ return False # ignore other commands
+ if first.lstrip().startswith("...") or first.lstrip().startswith("…"):
+ text = buf+text
+ usebuf = True
+ if not usebuf:
+ if first[-1] == ':':
+ return False
+ if not leading_cap(text):
+ return False
+ if (not (text.rstrip().endswith("...") or text.rstrip().endswith("…")
+ or text.lstrip().endswith("...") or text.lstrip().endswith("…")) and
+ len(text) < 13):
+ return False # too short
+ if len(text) > 130:
+ return False # too long
+ if (text.rstrip().endswith("...") or
+ text.rstrip().endswith("…")):
+ # it might be a call
+ buf = text
+ if usebuf:
+ lbuf.append(l)
+ else:
+ lbuf = [l]
+ return True
+ errors = template.check(text)
+ quiet = False
+ if errors:
+ print(errors.report())
+ if not errors:
+ buf = ""
+ if usebuf:
+ for bl in lbuf:
+ output(bl, descriptor)
+ output(l, descriptor)
+ lbuf = []
+ return not errors
+
+if len(sys.argv) not in [3, 4]:
+ print("Usage: %s TEMPLATE POEM [OFFSET]" % sys.argv[0], file=sys.stderr)
+ print("Check POEM according to TEMPLATE, add valid verse from stdin to POEM",
+ file=sys.stderr)
+ print("Ignore OFFSET lines from POEM",
+ file=sys.stderr)
+ sys.exit(1)
+
+localization.init_locale()
+
+f = open(sys.argv[1])
+x = f.read()
+f.close()
+template = Template(x)
+
+template.reject_errors = True
+
+offset = 0
+if len(sys.argv) == 4:
+ offset = int(sys.argv[3])
+
+pos = 0
+
+localization.init_locale()
+f = open(sys.argv[2], 'r')
+for line in f.readlines():
+ pos += 1
+ if pos <= offset:
+ continue # ignore first lines
+ print("%s (read)" % line.rstrip(), file=sys.stderr)
+ if not manage(line, sys.stderr):
+ print("Existing poem is wrong!", file=sys.stderr)
+ sys.exit(2)
+f.close()
+
+print("ready", file=sys.stderr)
+
+def run():
+ global lbuf
+ while True:
+ line = sys.stdin.readline()
+ if not line:
+ break
+ print("Seen: %s" % line, file=sys.stderr)
+ manage(' '.join(line.split(' ')[1:]))
+
+run()
+
diff --git a/poem2html/bottom.html b/poem2html/bottom.html
@@ -0,0 +1,3 @@
+ </div>
+ </body>
+</html>
diff --git a/poem2html/make_poem.pl b/poem2html/make_poem.pl
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use HTML::Entities;
+
+my $actor;
+my $indent;
+my $first = 1;
+my %actions;
+
+while (<STDIN>) {
+ chop;
+ if (/^<([^>]*)> \/me plint (.*)$/) {
+ if ($1 ne $actor) {
+ $actions{$1} = $2;
+ } else {
+ my $did = encode_entities($2, '<>&"');
+ print "</p>\n";
+ print "<p class=\"did\">$actor $did</p>\n";
+ print "<p class=\"speech\">\n";
+ }
+ } elsif (/^<([^>]*)> (.*)$/) {
+ if ($1 ne $actor) {
+ print "</p>\n" unless $first;
+ $first = 0;
+ $actor = $1;
+ my $eactor = encode_entities($actor, '<>&"');
+ print "<p class=\"actor\"><span class=\"actor\">$eactor</span>";
+ if (exists $actions{$1}) {
+ my $did = encode_entities($actions{$1}, '<>&"');
+ print ", <span class=\"did\">$did</span>";
+ delete $actions{$1};
+ }
+ print "</p>\n";
+ print "<p class=\"speech\">\n";
+ }
+ my $rawverse = $2;
+ if ($2 =~ m/^ *\.\.\./) {
+ $indent++;
+ } else {
+ $indent = 0;
+ }
+ my $verse = encode_entities($rawverse, '<>&"');
+ if ($indent) {
+ my $offset = 4 * $indent . "em";
+ print "<span style=\"margin-left: $offset;\">$verse</span><br />\n";
+ } else {
+ print "$verse<br />\n";
+ }
+ }
+}
+
+print "</p>\n" unless $first;
diff --git a/poem2html/make_poem.sh b/poem2html/make_poem.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+
+cat $DIR/top.html
+cat $1 | $DIR/make_poem.pl
+cat $DIR/bottom.html
diff --git a/poem2html/style.css b/poem2html/style.css
@@ -0,0 +1,117 @@
+body {
+ background-color: #ccc;
+ font-family: Arial, Helvetica, sans-serif;
+}
+
+h1,.subtitle {
+ font-family: monospace;
+ text-align: center;
+ margin-bottom: 0.5em;
+ margin-right: 2.5em;
+}
+
+hr {
+ margin-right: 5em;
+}
+
+.separator {
+ margin-top: 2.5em;
+ width: 50%;
+ margin-right: 10em;
+}
+
+#top {
+ margin-top: 0;
+ margin-bottom: 3em;
+}
+
+#container {
+ border: 1px solid #333;
+ background-color: white;
+ margin: auto;
+ padding-top: 1em;
+ padding-bottom: 1em;
+ padding-left: 5em;
+}
+
+.stanza {
+ margin-bottom: 1.25em;
+ margin-top: 1.25em;
+}
+
+#footer, .dedication {
+ text-align: right;
+}
+
+.dedication {
+ font-style: italic;
+ margin-bottom: 1.8em;
+ margin-right: 4em;
+}
+
+#footer {
+ margin-top: 3em;
+ margin-right: 1em;
+}
+
+.ref {
+ font-style: oblique;
+}
+
+#header {
+ margin-bottom: 3em;
+}
+
+h2 {
+ font-size: 150%;
+ margin-bottom: 0.2em;
+ margin-top: 1.5em;
+ letter-spacing: 1px;
+ font-variant: small-caps;
+}
+
+h3 {
+ font-size: 100%;
+ margin-top: 1.5em;
+}
+
+h2, h3 {
+ font-family: Georgia, "Times New Roman", Times, serif;
+}
+
+.ref {
+ text-align: left;
+ margin-left: 0;
+}
+
+#container {
+ max-width: 28em;
+}
+
+.line {
+ margin-top: 0.45em;
+ margin-bottom: 0.45em;
+}
+
+span.actor {
+ font-variant: small-caps;
+ margin-left: 2em;
+ margin-bottom: 0.3em;
+}
+
+.speech {
+ margin-top: 0.3em;
+}
+
+.subtitle {
+ font-size: 70%;
+}
+
+.did {
+ font-style: italic;
+}
+
+p.did {
+ margin-left: 2em;
+}
+
diff --git a/poem2html/top.html b/poem2html/top.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html dir="ltr" xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>#alexandrins</title>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <meta name="author" content="ulminfo" />
+ <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
+ </head>
+ <body>
+ <div id="container">
+ <h1>#alexandrins</h1>
+ <hr id="top" />
+