-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_page.py
178 lines (147 loc) · 3.74 KB
/
main_page.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Written by Juan Pablo Gutierrez
import machine
import socket
uploadedFile = ""
# Method that returns the web page
def webPage():
html = """
<!DOCTYPE html>
<html>
<head>
<title>Dalia</title>
<style>
p {
font-family: Arial;
margin-top: 0;
margin-bottom: 0;
}
.title {
color: black;
font-size: 25px;
font-weight: bold;
text-align: center;
}
.subtitle {
font-size: 15px;
font-weight: bold;
text-align: center;
color: rgb(96, 96, 96);
margin-top: 15px;
margin-bottom: 15px;
}
.submit-button {
background-color: rgb(4, 157, 228);
color: white;
border: none;
padding: 10px;
padding-left: 20px;
padding-right: 20px;
border-radius: 18px;
cursor: pointer;
font-weight: bold;
font-size: 15px;
transition: opacity 0.15s, box-shadow 0.15s;
}
.submit-button:hover {
opacity: 0.7;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
}
.upload-button:active {
opacity: 0.4;
}
.submit-button:active {
opacity: 0.4;
}
input {
display: none;
}
label {
font-family: Arial;
display: inline-block;
vertical-align: center;
text-align: center;
padding-left: 150px;
padding-right: 150px;
padding-top: 100px;
padding-bottom: 100px;
border-radius: 6px;
border: 1px dashed #999;
}
label:hover {
color: #de0611;
border: 1px dashed #de0611;
}
.file-paragraph {
display: flex;
justify-content: center;
align-items: center;
margin-top: 20px;
}
.file-uploader-div {
display: flex;
justify-content: center;
align-items: center;
}
.button-div {
display: flex;
justify-content: center;
align-items: center;
margin-top: 20px;
}
</style>
</head>
<body>
<p class="title"> Dalia Gcode uploader</p>
<p class="subtitle">Select a file to upload</p>
<div class="file-uploader-div">
<input type="file" id="file-input" accept=".gcode" />
<label for="file-input">Upload Gcode</label>
</div>
<p id="file-name" class="file-paragraph"></p>
<div class="button-div">
<button class="submit-button" id="submit-button">Submit</button>
</div>
<script>
const fileInput = document.getElementById('file-input');
const fileName = document.getElementById('file-name');
const uploadButton = document.getElementById('submit-button');
fileInput.addEventListener('change', function () {
const file = fileInput.files[0];
if (file) {
fileName.textContent = "File uploaded: " + file.name;
} else {
fileName.textContent = 'Failed to upload file';
}
});
uploadButton.addEventListener('click', function () {
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function () {
const contents = reader.result;
console.log('File contents:', contents);
};
reader.readAsText(file);
});
</script>
</body>
</html>
"""
return html
def runMain():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024)
request = str(request)
print('Content = %s' % request)
file = request.find('gcodeFile')
response = webPage()
conn.send('HTTP/1.1 200 OK\n')
conn.send('Content-Type: text/html\n')
conn.send('Connection: close\n\n')
conn.sendall(response)
conn.close()