Skip to content

Commit 92b6a60

Browse files
committed
Add script to generate HTML table from CSV data and create output directory
1 parent 532b79d commit 92b6a60

4 files changed

Lines changed: 688 additions & 0 deletions

File tree

.github/workflows/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output
File renamed without changes.

web_pages/build_packages_page.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import csv
2+
import datetime
3+
import shutil
4+
import os
5+
6+
def main(csv_file_path, html_file_path):
7+
print(f"Current working directory: {os.getcwd()}")
8+
9+
if not os.path.exists("output"):
10+
os.makedirs("output")
11+
12+
with open(html_file_path, 'w') as html_file:
13+
14+
# Put html together for this page
15+
head = '<!DOCTYPE html><html lang="en-GB">'
16+
head += '<head>'
17+
head += '<title>DataSHIELD packages</title>'
18+
head += '<meta charset="UTF-8">'
19+
head += '<link rel="stylesheet" href="./style_main.css">'
20+
head += '</head>'
21+
head += '<body>'
22+
23+
html_file.write(head)
24+
25+
with open(csv_file_path, 'r') as csv_file:
26+
reader = csv.reader(csv_file)
27+
headers = next(reader)
28+
29+
html_file.write('<h1>DataSHIELD packages</h1>\n')
30+
html_file.write('<table border="1">\n')
31+
html_file.write('<tr><td></td>' + ''.join(f'<th>{header}</th>' for header in headers) + '</tr>\n')
32+
33+
row_count = 0
34+
for row in reader:
35+
print(row)
36+
row_count += 1
37+
html_file.write('<tr>')
38+
html_file.write('<td>' + str(row_count) + '</td>') # Row number
39+
html_file.write('<td>' + row[0] + '</td>') # Name
40+
html_file.write('<td>' + row[1] + '</td>') # Description
41+
if len(row[2]) > 0:
42+
html_file.write('<td><a href="' + row[2] + '" target="blank">Link</a></td>') # CRAN link
43+
else:
44+
html_file.write('<td></td>')
45+
html_file.write('<td>' + row[3] + '</td>') # CRAN version
46+
html_file.write('<td>' + row[4] + '</td>') # CRAN license
47+
if len(row[5]) > 0:
48+
html_file.write('<td><a href="' + row[5] + '" target="blank">Link</a></td>') # GH repository
49+
else:
50+
html_file.write('<td></td>')
51+
html_file.write('<td>' + row[6] + '</td>') # GH last update
52+
html_file.write('<td>' + row[7] + '</td>') # GH version
53+
html_file.write('<td>' + row[8] + '</td>') # GH license
54+
html_file.write('<td>' + row[9] + '</td>') # GH owner
55+
html_file.write('</tr>\n')
56+
57+
html_file.write('</table>')
58+
59+
html_file.write('Generated on ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
60+
61+
html_file.write('</body>\n</html>')
62+
63+
if __name__ == '__main__':
64+
main('output.csv', './output/table.html')
65+
shutil.copy('./web_pages/template/style_main.css', './output/style_main.css')

0 commit comments

Comments
 (0)