-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgen_html.py
More file actions
153 lines (131 loc) · 4.38 KB
/
gen_html.py
File metadata and controls
153 lines (131 loc) · 4.38 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
143
144
145
146
147
148
149
150
151
152
153
part_1_html = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.topology.min.js"></script>
<div id="vanta-canvas" style="top: 0; left: 0; width: 100%; height: 100%; position: fixed; margin: 0; z-index: -5" width="1296" height="1103"></div>
<script>
VANTA.TOPOLOGY({
el: "#vanta-canvas",
mouseControls: true,
touchControls: true,
gyroControls: false,
minHeight: 200.00,
minWidth: 200.00,
scale: 0.30,
scaleMobile: 1.00,
color: 0x1e52fc,
backgroundColor: 0x0
})
</script>
<style>
body {
background-color: black;
color: white;
}
.container {
max-width: 600px;
margin: auto;
}
.server-list {
list-style: none;
padding: 0;
}
.server-item {
border: 1px solid #ffffff;
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
}
.server-name {
font-weight: bold;
}
.btn-choose {
margin-top: 10px;
margin-bottom: 10px;
/* button colors; */
background-color: rgb(29, 37, 66);
border-color: #151c33;
}
.credits {
position: fixed;
left: 5px;
bottom: 5px;
color: #ffffff27;
}
.hidden {
display: none;
}
</style>
<title>Server Choice</title>
</head>
<body>
<div class="container mt-5">
<h1 class="mb-4">Choose a Server</h1>
<ul class="server-list">"""
part_2_html = """
</ul>
<!-- Create hidden input so Flask can get content -->
<form id="serverForm" method="post" action="{{ url_for('handle_server') }}">
<input type="hidden" name="server" id="serverInput" value="">
</form>
</div>
<div class="credits">@cloudzikk | @b3n.j4m1n</div>
<!-- Bootstrap JS and Popper.js (required for Bootstrap components) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
function chooseServer(serverName) {
// Set the server input value
document.getElementById('serverInput').value = serverName;
// Submit the form
document.getElementById('serverForm').submit();
}
</script>
</body>
</html>
"""
def generate_html(names: int):
if len(names) == 0:
names = ["No Servers Found"]
if len(names) > 1:
custom_parts = []
i = 0
for name in names:
try:
name = name.replace("'", "")
except:
pass
custom_part = f"""
<!-- Server 2 -->
<li class="server-item">
<span class="server-name">{name}</span>
<button class="btn btn-primary btn-choose" onclick="chooseServer('{i}')">Choose</button>
</li>"""
i += 1
custom_parts.append(custom_part)
else:
name = names[0]
try:
name = name.replace("'", "")
except:
name = name
custom_parts = []
custom_part = f"""
<!-- Server 2 -->
<li class="server-item">
<span class="server-name">{names[0]}</span>
<button class="btn btn-primary btn-choose" onclick="chooseServer('0')">Choose</button>
</li>"""
custom_parts.append(custom_part)
custom_parts = "\n".join(custom_parts)
html = part_1_html + custom_parts + part_2_html
with open("pages/serverlist.html", "w") as f:
f.write(html)