aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-01-19 18:10:31 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2026-01-19 18:10:31 +0100
commit046d9c920ac2439d02a18517083449f0e99f9e9d (patch)
tree252ee12222cf18e6ad9e50211e0b899df7007b2e
parent7134160ada7a3e08d4c463bcc410043125a203c5 (diff)
downloadspgen-046d9c920ac2439d02a18517083449f0e99f9e9d.tar.gz
spgen-046d9c920ac2439d02a18517083449f0e99f9e9d.zip
add and support HTML templatesHEADmain
-rw-r--r--Readme.md16
-rwxr-xr-xspgen.py21
-rw-r--r--templates/8,9,9,4.html83
3 files changed, 112 insertions, 8 deletions
diff --git a/Readme.md b/Readme.md
index 07b6e17..1e9e007 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,4 +1,4 @@
-# simple script to generate random seating plans using LaTeX templates
+# simple script to generate random seating plans using templates
## Usage
@@ -15,18 +15,24 @@ options:
```
+Pipeline to generate a HTML seating plan from a Infoportal csv class list.
+
+```sh
+cat Klassenliste.csv | cut -f2 -d';' | ./spgen.py templates/8,9,9,4.html --seats=n > class.html
+```
+
## Available Templates
```
templates
-└── 4x(2,5).tex
-
-1 directory, 1 file
+├── 4x(2,5).tex
+├── 8,9,9,4.html
+└── 8,9,9,4.tex
```
## Requirements
-* python >= 3.11
+* python >= 3.10
The requirements can be installed in virtual environment using [`pipenv`](https://pipenv.pypa.io/).
diff --git a/spgen.py b/spgen.py
index 42ddfed..a72f440 100755
--- a/spgen.py
+++ b/spgen.py
@@ -8,6 +8,10 @@ import sys
class SPTemplate(Template):
+ """Seating plan template
+
+ %% is used as delimiter because the most templates are written in LaTeX.
+ """
delimiter = '%%'
@@ -15,11 +19,22 @@ def print_sp_template(template: SPTemplate, duration: str, names: list[str],
seats: list[int]):
"""Print the template including our name definitions"""
defs = []
- for name in names:
- seat = seats.pop()
+ seating = {i: '' for i in range(1, 33)}
+ for i, name in enumerate(names):
+ seat = seats[i]
+ seating[seat] = name
defs.append(rf'\csdef{{name{seat}}}{{{name}}}')
+
defs.append(rf'\csdef{{duration}}{{{duration}}}')
- print(template.substitute({'defs': '\n'.join(defs)}))
+
+ subs = {
+ 'defs': '\n'.join(defs)
+ } | {
+ f'name{seat}': name
+ for seat, name in seating.items()
+ }
+
+ print(template.substitute(subs))
def main():
diff --git a/templates/8,9,9,4.html b/templates/8,9,9,4.html
new file mode 100644
index 0000000..f087d48
--- /dev/null
+++ b/templates/8,9,9,4.html
@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" lang xml:lang>
+<head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
+ <title>Sitzplan</title>
+ <style>
+ td {
+ border: solid;
+ }
+ td.sep {
+ width: 5em;
+ border: none;
+ }
+ </style>
+</head>
+<body>
+<table>
+ <tr>
+ <td class="c1">%%name1</td>
+ <td class="sep"></td>
+ <td class="c2">%%name9</td>
+ <td class="c3">%%name10</td>
+ </tr>
+ <tr>
+ <td class="c1">%%name2</td>
+ <td class="sep"></td>
+ <td class="c2">%%name11</td>
+ <td class="c3">%%name12</td>
+ <td class="sep"></td>
+ <td class="c4">%%name27</td>
+ </tr>
+ <tr>
+ <td class="c1">%%name3</td>
+ <td class="sep"></td>
+ <td class="c2">%%name13</td>
+ <td class="c3">%%name14</td>
+ <td class="sep"></td>
+ <td class="c4">%%name28</td>
+ </tr>
+ <tr>
+ <td class="c1">%%name4</td>
+ <td class="sep"></td>
+ <td class="c2">%%name15</td>
+ <td class="c3">%%name16</td>
+ <td class="sep"></td>
+ <td class="c4">%%name29</td>
+ </tr>
+ <tr>
+ <td class="c1">%%name5</td>
+ <td class="sep"></td>
+ <td class="c2">%%name17</td>
+ <td class="c3">%%name18</td>
+ <td class="sep"></td>
+ <td class="c4">%%name30</td>
+ </tr>
+ <tr>
+ <td class="c1">%%name6</td>
+ <td class="sep"></td>
+ <td class="c2">%%name19</td>
+ <td class="c3">%%name20</td>
+ </tr>
+ <tr>
+ <td class="c1">%%name7</td>
+ <td class="sep"></td>
+ <td class="c2">%%name21</td>
+ <td class="c3">%%name22</td>
+ </tr>
+ <tr>
+ <td class="c1">%%name8</td>
+ <td class="sep"></td>
+ <td class="c2">%%name23</td>
+ <td class="c3">%%name24</td>
+ </tr>
+ <tr>
+ <td class="c1" style="border: none;"></td>
+ <td class="sep"></td>
+ <td class="c2">%%name25</td>
+ <td class="c3">%%name26</td>
+ </tr>
+</table>
+</body>
+</html>