Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,6 @@ if not os.path.exists(UPLOAD_FOLDER):
|
|
28 |
|
29 |
|
30 |
|
31 |
-
|
32 |
# Создание базы данных и таблицы
|
33 |
def init_db():
|
34 |
try:
|
@@ -109,19 +108,19 @@ def online():
|
|
109 |
@app.route('/upload', methods=['POST'])
|
110 |
def upload_file():
|
111 |
if 'photo' not in request.files:
|
112 |
-
return jsonify({
|
113 |
file = request.files['photo']
|
114 |
if file.filename == '':
|
115 |
-
return jsonify({
|
116 |
save_path = os.path.join(UPLOAD_FOLDER, IMAGE_FILENAME)
|
117 |
file.save(save_path)
|
118 |
-
return jsonify({
|
119 |
|
120 |
@app.route('/image', methods=['GET'])
|
121 |
def get_image():
|
122 |
return send_from_directory(UPLOAD_FOLDER, IMAGE_FILENAME)
|
123 |
|
124 |
-
@app.route('/
|
125 |
def index():
|
126 |
html = '''
|
127 |
<!DOCTYPE html>
|
@@ -129,7 +128,7 @@ def index():
|
|
129 |
<head>
|
130 |
<meta charset="UTF-8">
|
131 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
132 |
-
<title>Send Messages</title>
|
133 |
<style>
|
134 |
body {
|
135 |
font-family: Arial, sans-serif;
|
@@ -194,34 +193,27 @@ def index():
|
|
194 |
</style>
|
195 |
</head>
|
196 |
<body>
|
197 |
-
<h1>Отправка сообщения
|
198 |
<div class="input-row">
|
199 |
<input type="text" id="apiKeyInput" placeholder="Введите API ключ">
|
200 |
<input type="number" id="minDelayInput" placeholder="Min Delay (ms)" value="500">
|
201 |
<input type="number" id="maxDelayInput" placeholder="Max Delay (ms)" value="1000">
|
202 |
-
<label>
|
203 |
-
Показывать превью:
|
204 |
-
<input type="checkbox" id="linkPreviewCheckbox" checked>
|
205 |
-
</label>
|
206 |
</div>
|
207 |
-
<textarea id="messageInput" placeholder="Введите текст
|
|
|
|
|
208 |
<div id="progressBarContainer">
|
209 |
<div id="progressBar">
|
210 |
<div id="progress">0%</div>
|
211 |
</div>
|
212 |
</div>
|
213 |
-
<input type="file" id="fileInput" accept=".txt">
|
214 |
-
<button id="sendButton">Запустить рассылку</button>
|
215 |
-
|
216 |
-
<h1>Upload Image</h1>
|
217 |
<form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload">
|
218 |
<input type="file" name="photo" id="photoInput">
|
219 |
-
<button type="submit"
|
220 |
</form>
|
221 |
-
<div id="
|
222 |
-
<h1
|
223 |
-
<img id="cameraImage" src="" alt="
|
224 |
-
|
225 |
<script>
|
226 |
document.getElementById('uploadForm').addEventListener('submit', function(event) {
|
227 |
event.preventDefault();
|
@@ -232,16 +224,14 @@ def index():
|
|
232 |
})
|
233 |
.then(response => response.json())
|
234 |
.then(data => {
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
document.getElementById('uploadedFileName').innerText = data.file_name;
|
241 |
-
}
|
242 |
})
|
243 |
.catch(error => {
|
244 |
-
document.getElementById('
|
245 |
});
|
246 |
});
|
247 |
|
@@ -250,7 +240,9 @@ def index():
|
|
250 |
const message = document.getElementById('messageInput').value;
|
251 |
const minDelay = parseInt(document.getElementById('minDelayInput').value) || 500;
|
252 |
const maxDelay = parseInt(document.getElementById('maxDelayInput').value) || 10000;
|
253 |
-
const
|
|
|
|
|
254 |
if (!apiKey) {
|
255 |
alert('Please enter your API key.');
|
256 |
return;
|
@@ -263,6 +255,11 @@ def index():
|
|
263 |
alert('Min delay must be less than max delay.');
|
264 |
return;
|
265 |
}
|
|
|
|
|
|
|
|
|
|
|
266 |
const fileInput = document.getElementById('fileInput');
|
267 |
const file = fileInput.files[0];
|
268 |
if (!file) {
|
@@ -273,26 +270,27 @@ def index():
|
|
273 |
reader.onload = function(event) {
|
274 |
const text = event.target.result;
|
275 |
const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
|
276 |
-
sendMessages(phones, apiKey, message, minDelay, maxDelay,
|
277 |
};
|
278 |
reader.readAsText(file);
|
279 |
});
|
280 |
|
281 |
-
async function sendMessages(phones, apiKey, message, minDelay, maxDelay,
|
282 |
const totalPhones = phones.length;
|
283 |
const progressBar = document.getElementById('progress');
|
284 |
for (let i = 0; i < totalPhones; i++) {
|
285 |
const phone = phones[i];
|
286 |
try {
|
287 |
-
const response = await fetch(`https://api.green-api.com/waInstance1101952913/
|
288 |
method: 'POST',
|
289 |
headers: {
|
290 |
'Content-Type': 'application/json'
|
291 |
},
|
292 |
body: JSON.stringify({
|
293 |
chatId: `${phone}@c.us`,
|
294 |
-
|
295 |
-
|
|
|
296 |
})
|
297 |
});
|
298 |
if (!response.ok) {
|
@@ -331,7 +329,6 @@ def index():
|
|
331 |
|
332 |
|
333 |
|
334 |
-
|
335 |
# Маршрут для обработки GET-запроса
|
336 |
@app.route('/add_contact', methods=['GET'])
|
337 |
def add_contact():
|
|
|
28 |
|
29 |
|
30 |
|
|
|
31 |
# Создание базы данных и таблицы
|
32 |
def init_db():
|
33 |
try:
|
|
|
108 |
@app.route('/upload', methods=['POST'])
|
109 |
def upload_file():
|
110 |
if 'photo' not in request.files:
|
111 |
+
return jsonify({"message": "No file part"}), 400
|
112 |
file = request.files['photo']
|
113 |
if file.filename == '':
|
114 |
+
return jsonify({"message": "No selected file"}), 400
|
115 |
save_path = os.path.join(UPLOAD_FOLDER, IMAGE_FILENAME)
|
116 |
file.save(save_path)
|
117 |
+
return jsonify({"message": "File uploaded successfully", "file_url": "/image", "file_name": file.filename}), 200
|
118 |
|
119 |
@app.route('/image', methods=['GET'])
|
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>
|
|
|
128 |
<head>
|
129 |
<meta charset="UTF-8">
|
130 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
131 |
+
<title>Send Messages with Image</title>
|
132 |
<style>
|
133 |
body {
|
134 |
font-family: Arial, sans-serif;
|
|
|
193 |
</style>
|
194 |
</head>
|
195 |
<body>
|
196 |
+
<h1>Отправка сообщения с изображением</h1>
|
197 |
<div class="input-row">
|
198 |
<input type="text" id="apiKeyInput" placeholder="Введите API ключ">
|
199 |
<input type="number" id="minDelayInput" placeholder="Min Delay (ms)" value="500">
|
200 |
<input type="number" id="maxDelayInput" placeholder="Max Delay (ms)" value="1000">
|
|
|
|
|
|
|
|
|
201 |
</div>
|
202 |
+
<textarea id="messageInput" placeholder="Введите текст сообщения"></textarea>
|
203 |
+
<input type="file" id="fileInput" accept=".txt">
|
204 |
+
<button id="sendButton">Запустить рассылку</button>
|
205 |
<div id="progressBarContainer">
|
206 |
<div id="progressBar">
|
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();
|
|
|
224 |
})
|
225 |
.then(response => response.json())
|
226 |
.then(data => {
|
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;
|
235 |
});
|
236 |
});
|
237 |
|
|
|
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.');
|
248 |
return;
|
|
|
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];
|
265 |
if (!file) {
|
|
|
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) {
|
|
|
329 |
|
330 |
|
331 |
|
|
|
332 |
# Маршрут для обработки GET-запроса
|
333 |
@app.route('/add_contact', methods=['GET'])
|
334 |
def add_contact():
|