forked from PyLink/PyLink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelists-genhtml.py
More file actions
executable file
·142 lines (116 loc) · 3.18 KB
/
modelists-genhtml.py
File metadata and controls
executable file
·142 lines (116 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""
Generates HTML versions of the mode list .csv definitions.
"""
import csv
import os
import os.path
os.chdir(os.path.dirname(__file__))
FILES = {
'user-modes.csv': 'Supported User Modes for PyLink',
'channel-modes.csv': 'Supported Channel Modes for PyLink',
'extbans.csv': 'Supported Extbans for PyLink',
}
def _write(outf, text):
print(text, end='')
outf.write(text)
def _format(articlename, text):
# More formatting
if text:
if text.startswith('('):
text = '<td class="tablecell-partial">%s</td>' % text
else:
if 'modes' in articlename:
text = '+' + text
try:
text, note = text.split(' ', 1)
except ValueError:
if text.endswith('*'):
text = '<td class="tablecell-special">%s</td>' % text
else:
text = '<td class="tablecell-yes">%s</td>' % text
else:
text = '%s<br><span class="note">%s</span>' % (text, note)
text = '<td class="tablecell-yes2">%s</td>' % text
else:
text = '<td class="tablecell-na note">n/a</td>'
return text
for fname, title in FILES.items():
outfname = os.path.splitext(fname)[0] + '.html'
print('Generating HTML for %s to %s:' % (fname, outfname))
with open(fname) as csvfile:
csvdata = csv.reader(csvfile)
with open(outfname, 'w') as outf:
# CSS in HTML in Python, how lovely...
_write(outf, """
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name=viewport content="width=device-width, initial-scale=1">
<head>
<title>%s</title>
<style>
html {
background-color: white;
}
.note {
color: #555555;
}
/* (╮°-°)╮┳━┳ */
table, th, td {
border: 1px solid black;
}
td, th {
text-align: center;
padding: 3px;
}
td:first-child, th[scope="row"] {
text-align: left;
}
/* Table cells */
.tablecell-yes {
background-color: #A7F2A5
}
.tablecell-no {
background-color: #F08496
}
.tablecell-na {
background-color: #F0F0F0
}
.tablecell-planned, .tablecell-yes2 {
background-color: #B1FCDE
}
.tablecell-partial {
background-color: #EDE8A4
}
.tablecell-special {
background-color: #DCB1FC
}
</style>
</head>
<body>
<table>""" % title)
notes = False
for idx, row in enumerate(csvdata):
if not any(row): # Empty row
continue
elif row[0] == '----':
notes = True
continue
if notes:
_write(outf, "<p>%s</p>" % row[0])
continue
_write(outf, "<tr>\n")
for colidx, coltext in enumerate(row):
if idx == 0:
text = '<th scope="col">%s</th>\n' % coltext
elif colidx == 0:
text = '<th scope="row">%s</th>\n' % coltext
else:
text = _format(fname, coltext)
_write(outf, text)
_write(outf, "</tr>\n")
_write(outf, """
</table>
</body>
</html>""")