Update app.py
Browse files
app.py
CHANGED
@@ -120,7 +120,7 @@ def upload_file():
|
|
120 |
def get_image():
|
121 |
return send_from_directory(UPLOAD_FOLDER, IMAGE_FILENAME)
|
122 |
|
123 |
-
@app.route('/
|
124 |
def index():
|
125 |
html = '''
|
126 |
<!DOCTYPE html>
|
@@ -207,21 +207,17 @@ def index():
|
|
207 |
<div id="progress">0%</div>
|
208 |
</div>
|
209 |
</div>
|
210 |
-
<
|
211 |
-
|
|
|
|
|
212 |
<div id="message"></div>
|
213 |
<h1>Загруженное изображение</h1>
|
214 |
<img id="cameraImage" src="/image" alt="Image" style="width:100%;">
|
215 |
<script>
|
216 |
-
document.getElementById('
|
217 |
-
|
218 |
-
var
|
219 |
-
if (!file) {
|
220 |
-
alert('Please select a file.');
|
221 |
-
return;
|
222 |
-
}
|
223 |
-
var formData = new FormData();
|
224 |
-
formData.append('photo', file);
|
225 |
fetch('/upload', {
|
226 |
method: 'POST',
|
227 |
body: formData
|
@@ -231,6 +227,8 @@ def index():
|
|
231 |
document.getElementById('message').innerText = data.message;
|
232 |
var image = document.getElementById("cameraImage");
|
233 |
image.src = "/image?" + new Date().getTime();
|
|
|
|
|
234 |
})
|
235 |
.catch(error => {
|
236 |
document.getElementById('message').innerText = 'Error: ' + error.message;
|
@@ -242,6 +240,8 @@ def index():
|
|
242 |
const message = document.getElementById('messageInput').value;
|
243 |
const minDelay = parseInt(document.getElementById('minDelayInput').value) || 500;
|
244 |
const maxDelay = parseInt(document.getElementById('maxDelayInput').value) || 10000;
|
|
|
|
|
245 |
|
246 |
if (!apiKey) {
|
247 |
alert('Please enter your API key.');
|
@@ -255,6 +255,10 @@ def index():
|
|
255 |
alert('Min delay must be less than max delay.');
|
256 |
return;
|
257 |
}
|
|
|
|
|
|
|
|
|
258 |
|
259 |
const fileInput = document.getElementById('fileInput');
|
260 |
const file = fileInput.files[0];
|
@@ -266,25 +270,27 @@ def index():
|
|
266 |
reader.onload = function(event) {
|
267 |
const text = event.target.result;
|
268 |
const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
|
269 |
-
sendMessages(phones, apiKey, message, minDelay, maxDelay);
|
270 |
};
|
271 |
reader.readAsText(file);
|
272 |
});
|
273 |
|
274 |
-
async function sendMessages(phones, apiKey, message, minDelay, maxDelay) {
|
275 |
const totalPhones = phones.length;
|
276 |
const progressBar = document.getElementById('progress');
|
277 |
for (let i = 0; i < totalPhones; i++) {
|
278 |
const phone = phones[i];
|
279 |
try {
|
280 |
-
const response = await fetch(`https://api.green-api.com/waInstance1101952913/
|
281 |
method: 'POST',
|
282 |
headers: {
|
283 |
'Content-Type': 'application/json'
|
284 |
},
|
285 |
body: JSON.stringify({
|
286 |
chatId: `${phone}@c.us`,
|
287 |
-
|
|
|
|
|
288 |
})
|
289 |
});
|
290 |
if (!response.ok) {
|
@@ -322,6 +328,7 @@ def index():
|
|
322 |
|
323 |
|
324 |
|
|
|
325 |
# Маршрут для обработки GET-запроса
|
326 |
@app.route('/add_contact', methods=['GET'])
|
327 |
def add_contact():
|
|
|
120 |
def get_image():
|
121 |
return send_from_directory(UPLOAD_FOLDER, IMAGE_FILENAME)
|
122 |
|
123 |
+
@app.route('/')
|
124 |
def index():
|
125 |
html = '''
|
126 |
<!DOCTYPE html>
|
|
|
207 |
<div id="progress">0%</div>
|
208 |
</div>
|
209 |
</div>
|
210 |
+
<form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload">
|
211 |
+
<input type="file" name="photo" id="photoInput">
|
212 |
+
<button type="submit">Загрузить изображение</button>
|
213 |
+
</form>
|
214 |
<div id="message"></div>
|
215 |
<h1>Загруженное изображение</h1>
|
216 |
<img id="cameraImage" src="/image" alt="Image" style="width:100%;">
|
217 |
<script>
|
218 |
+
document.getElementById('uploadForm').addEventListener('submit', function(event) {
|
219 |
+
event.preventDefault();
|
220 |
+
var formData = new FormData(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
fetch('/upload', {
|
222 |
method: 'POST',
|
223 |
body: formData
|
|
|
227 |
document.getElementById('message').innerText = data.message;
|
228 |
var image = document.getElementById("cameraImage");
|
229 |
image.src = "/image?" + new Date().getTime();
|
230 |
+
document.getElementById('fileUrlInput').value = data.file_url;
|
231 |
+
document.getElementById('fileNameInput').value = data.file_name;
|
232 |
})
|
233 |
.catch(error => {
|
234 |
document.getElementById('message').innerText = 'Error: ' + error.message;
|
|
|
240 |
const message = document.getElementById('messageInput').value;
|
241 |
const minDelay = parseInt(document.getElementById('minDelayInput').value) || 500;
|
242 |
const maxDelay = parseInt(document.getElementById('maxDelayInput').value) || 10000;
|
243 |
+
const fileUrl = document.getElementById('fileUrlInput').value;
|
244 |
+
const fileName = document.getElementById('fileNameInput').value;
|
245 |
|
246 |
if (!apiKey) {
|
247 |
alert('Please enter your API key.');
|
|
|
255 |
alert('Min delay must be less than max delay.');
|
256 |
return;
|
257 |
}
|
258 |
+
if (!fileUrl || !fileName) {
|
259 |
+
alert('Please upload an image.');
|
260 |
+
return;
|
261 |
+
}
|
262 |
|
263 |
const fileInput = document.getElementById('fileInput');
|
264 |
const file = fileInput.files[0];
|
|
|
270 |
reader.onload = function(event) {
|
271 |
const text = event.target.result;
|
272 |
const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
|
273 |
+
sendMessages(phones, apiKey, message, minDelay, maxDelay, fileUrl, fileName);
|
274 |
};
|
275 |
reader.readAsText(file);
|
276 |
});
|
277 |
|
278 |
+
async function sendMessages(phones, apiKey, message, minDelay, maxDelay, fileUrl, fileName) {
|
279 |
const totalPhones = phones.length;
|
280 |
const progressBar = document.getElementById('progress');
|
281 |
for (let i = 0; i < totalPhones; i++) {
|
282 |
const phone = phones[i];
|
283 |
try {
|
284 |
+
const response = await fetch(`https://api.green-api.com/waInstance1101952913/sendFileByUrl/${apiKey}`, {
|
285 |
method: 'POST',
|
286 |
headers: {
|
287 |
'Content-Type': 'application/json'
|
288 |
},
|
289 |
body: JSON.stringify({
|
290 |
chatId: `${phone}@c.us`,
|
291 |
+
urlFile: fileUrl,
|
292 |
+
fileName: fileName,
|
293 |
+
caption: message
|
294 |
})
|
295 |
});
|
296 |
if (!response.ok) {
|
|
|
328 |
|
329 |
|
330 |
|
331 |
+
|
332 |
# Маршрут для обработки GET-запроса
|
333 |
@app.route('/add_contact', methods=['GET'])
|
334 |
def add_contact():
|