-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
34 lines (28 loc) · 982 Bytes
/
script.py
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
import json
import fileinput
import shutil
# Define the source and destination file paths
source_file = 'index.html'
destination_file = 'build/code.html'
# Copy the source file to the destination folder
shutil.copyfile(source_file, destination_file)
# Generate the HTML code from JSON data
with open('data.json') as f:
data = json.load(f)
html = '<div id="PYTHON_GENERATED">'
for d in data:
html += f"""
<div className="M_ShortcutCard">
<a href={d['link']}>
<h1 className="A_CardName"><span className="Q_TextSelection">{d['selected']} </span> {d['text']}</h1>
<h2 className="A_CardKey">{d['windows']}, {d['macos']}</h2>
</a>
</div>
"""
html += '</div>'
# Replace the target element with the generated HTML code in the destination file
for line in fileinput.input(destination_file, inplace=True):
if 'id="PYTHON_REPLACE"' in line:
print(html)
else:
print(line, end='')