-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_code
59 lines (53 loc) · 2.06 KB
/
python_code
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
import re
import airium
def table_to_html(table_address, delineator, filename_html):
table = open(table_address, "r")
list = []
for line in table.readlines():
x = re.split("\\n", line)
y = str(x[0])
z = re.split(delineator, y)
list.append(z)
table.close()
a = airium.Airium()
with open(filename_html, 'w') as f:
a('<!DOCTYPE html>')
with a.html(lang="pl"):
with a.head():
a.meta(charset="utf-8")
a.meta(name="viewport", content="width=device-width, initial-scale=1.0")
with a.title():
a(filename_html)
with a.style():
a("th, td \n"
"\t\t{padding: 3px;}\n"
"\ttr:hover \n"
"\t\t{background-color: #D3D3D3;}\n"
"\ttable, th, td {\n"
"\t\tborder: 1px solid black;\n"
"\t\tborder-collapse: collapse;}")
with a.body():
with a.table():
with a.tbody():
for i in list:
index_i = list.index(i)
with a.tr():
for j in i:
if index_i == 0:
with a.th(style="background-color:#D3D3D3;"):
a(j)
else:
with a.td():
a(j)
html = str(a)
f.write(html)
f.close()
# To use the function:
# TSV Source File
table_address = "C:\\folder1\\folder2\\folder3\\folder4\\tsv_example.tsv"
filename_html = "tsv_example.html"
table_to_html(table_address, "\t", filename_html)
# CSV Source File
table_address = "C:\\folder1\\folder2\\folder3\\folder4\\csv_example.csv"
filename_html = "csv_example.html"
table_to_html(table_address, ",", filename_html)