DmitrMakeev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,76 +1,251 @@
|
|
1 |
-
from flask import Flask, request, render_template_string,
|
2 |
-
from flask import render_template
|
3 |
import sqlite3
|
4 |
import os
|
5 |
-
import
|
6 |
-
|
|
|
|
|
7 |
import json
|
8 |
import base64
|
9 |
-
import unittest
|
10 |
-
import requests
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
gc_url = os.getenv('gc_url')
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
-
import json
|
21 |
-
from datetime import datetime
|
22 |
|
23 |
-
import whatsapp_api_webhook_server_python.webhooksHandler as handler
|
24 |
|
25 |
app = Flask(__name__, template_folder="./")
|
|
|
|
|
26 |
|
|
|
|
|
27 |
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
|
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
os.makedirs(UPLOAD_FOLDER)
|
38 |
|
|
|
|
|
39 |
|
|
|
40 |
|
41 |
-
# Создание базы данных и таблицы
|
42 |
-
DATABASES = ['data1.db', 'data2.db', 'data3.db', 'data4.db', 'data5.db']
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
try:
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
cursor = conn.cursor()
|
48 |
-
cursor.execute(''
|
49 |
-
CREATE TABLE IF NOT EXISTS contacts (
|
50 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
51 |
-
name TEXT NOT NULL,
|
52 |
-
phone TEXT NOT NULL,
|
53 |
-
email TEXT NOT NULL
|
54 |
-
)
|
55 |
-
''')
|
56 |
conn.commit()
|
57 |
conn.close()
|
|
|
|
|
58 |
except Exception as e:
|
59 |
-
print(f"Error
|
|
|
60 |
|
61 |
-
|
62 |
-
|
|
|
|
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
|
66 |
-
@app.route('/settings', methods=['GET'])
|
67 |
-
def settings():
|
68 |
-
return render_template('settings.html')
|
69 |
|
70 |
|
71 |
-
@app.route('/online', methods=['GET'])
|
72 |
-
def onli():
|
73 |
-
return render_template('online.html')
|
74 |
|
75 |
|
76 |
|
@@ -80,95 +255,104 @@ def onli():
|
|
80 |
|
81 |
@app.route('/ver', methods=['GET'])
|
82 |
def veref():
|
|
|
|
|
|
|
83 |
return render_template('ver.html')
|
84 |
|
85 |
@app.route('/se_mes', methods=['GET'])
|
86 |
def se_mes():
|
|
|
|
|
|
|
87 |
return render_template('se_mes.html')
|
88 |
|
89 |
@app.route('/se_mes_im', methods=['GET'])
|
90 |
def se_mes_im():
|
|
|
|
|
|
|
91 |
return render_template('se_mes_im.html')
|
92 |
|
93 |
-
|
94 |
-
|
95 |
@app.route('/se_mes_ran', methods=['GET'])
|
96 |
def se_mes_ran():
|
|
|
|
|
|
|
97 |
return render_template('se_mes_ran.html')
|
98 |
|
99 |
-
|
100 |
-
|
101 |
@app.route('/se_mes_im_ran', methods=['GET'])
|
102 |
def se_mes_im_ran():
|
|
|
|
|
|
|
103 |
return render_template('se_mes_im_ran.html')
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
@app.route('/se_mes_im2', methods=['GET'])
|
111 |
def se_mes_im2():
|
|
|
|
|
|
|
112 |
return render_template('se_mes_im2.html')
|
113 |
|
114 |
@app.route('/se_mes_f', methods=['GET'])
|
115 |
def se_mes_f():
|
|
|
|
|
|
|
116 |
return render_template('se_mes_f.html')
|
117 |
|
118 |
@app.route('/up_gr', methods=['GET'])
|
119 |
def up_gr():
|
|
|
|
|
|
|
120 |
return render_template('up_gr.html')
|
121 |
|
122 |
@app.route('/up_user_gp', methods=['GET'])
|
123 |
def up_user_gp():
|
|
|
|
|
|
|
124 |
return render_template('up_user_gp.html')
|
125 |
|
126 |
@app.route('/del_user_gp', methods=['GET'])
|
127 |
def del_user_gp():
|
|
|
|
|
|
|
128 |
return render_template('del_user_gp.html')
|
129 |
|
130 |
@app.route('/up_ad', methods=['GET'])
|
131 |
def up_ad():
|
|
|
|
|
|
|
132 |
return render_template('up_ad.html')
|
133 |
|
134 |
@app.route('/del_ad', methods=['GET'])
|
135 |
def del_ad():
|
|
|
|
|
|
|
136 |
return render_template('del_ad.html')
|
137 |
-
|
138 |
@app.route('/se_opr', methods=['GET'])
|
139 |
def se_opr():
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
143 |
|
144 |
@app.route('/online', methods=['GET'])
|
145 |
def online():
|
|
|
|
|
|
|
146 |
return render_template('online.html')
|
147 |
|
148 |
-
@app.route('/upload', methods=['POST'])
|
149 |
-
def upload_file():
|
150 |
-
if 'file' not in request.files:
|
151 |
-
return "No file part", 400
|
152 |
-
file = request.files['file']
|
153 |
-
if file.filename == '':
|
154 |
-
return "No selected file", 400
|
155 |
-
|
156 |
-
# Генерация уникального имени файла
|
157 |
-
unique_filename = str(uuid.uuid4()) + os.path.splitext(file.filename)[1]
|
158 |
-
save_path = os.path.join(UPLOAD_FOLDER, unique_filename)
|
159 |
-
file.save(save_path)
|
160 |
-
|
161 |
-
# Возвращаем полный URL загруженного файла с протоколом https
|
162 |
-
full_url = request.url_root.replace('http://', 'https://') + 'uploads/' + unique_filename
|
163 |
-
return f"File uploaded successfully and saved to {full_url}", 200
|
164 |
|
165 |
-
@app.route('/uploads/<filename>', methods=['GET'])
|
166 |
-
def uploaded_file(filename):
|
167 |
-
return send_from_directory(UPLOAD_FOLDER, filename)
|
168 |
|
169 |
-
@app.route('/up_fa', methods=['GET'])
|
170 |
-
def up_fa():
|
171 |
-
return render_template('up_fa.html')
|
172 |
|
173 |
|
174 |
|
@@ -176,163 +360,238 @@ def up_fa():
|
|
176 |
|
177 |
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
try:
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
-
if not name or not phone or not email:
|
188 |
-
return "Parameters 'name', 'phone', and 'email' are required.", 400
|
189 |
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
cursor = conn.cursor()
|
192 |
-
cursor.execute('
|
193 |
-
|
194 |
conn.close()
|
195 |
|
196 |
-
return
|
197 |
except Exception as e:
|
198 |
-
print(f"Error
|
199 |
return "Internal Server Error", 500
|
200 |
|
201 |
-
|
202 |
-
|
|
|
|
|
203 |
try:
|
|
|
|
|
|
|
|
|
|
|
204 |
conn = sqlite3.connect('data1.db')
|
205 |
cursor = conn.cursor()
|
206 |
cursor.execute('SELECT name, phone, email FROM contacts')
|
207 |
contacts = cursor.fetchall()
|
208 |
conn.close()
|
209 |
|
210 |
-
|
211 |
-
<!doctype html>
|
212 |
-
<html lang="en">
|
213 |
-
<head>
|
214 |
-
<meta charset="utf-8">
|
215 |
-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
216 |
-
<title>Contacts</title>
|
217 |
-
<style>
|
218 |
-
table {
|
219 |
-
width: 70%;
|
220 |
-
border-collapse: collapse;
|
221 |
-
}
|
222 |
-
th, td {
|
223 |
-
border: 1px solid black;
|
224 |
-
padding: 8px;
|
225 |
-
text-align: left;
|
226 |
-
}
|
227 |
-
th {
|
228 |
-
background-color: #f2f2f2;
|
229 |
-
}
|
230 |
-
</style>
|
231 |
-
</head>
|
232 |
-
<body>
|
233 |
-
<h1>Contacts</h1>
|
234 |
-
<table>
|
235 |
-
<tr>
|
236 |
-
<th>Name</th>
|
237 |
-
<th>Phone</th>
|
238 |
-
<th>Email</th>
|
239 |
-
</tr>
|
240 |
-
{% for contact in contacts %}
|
241 |
-
<tr>
|
242 |
-
<td>{{ contact[0] }}</td>
|
243 |
-
<td>{{ contact[1] }}</td>
|
244 |
-
<td>{{ contact[2] }}</td>
|
245 |
-
</tr>
|
246 |
-
{% endfor %}
|
247 |
-
</table>
|
248 |
-
</body>
|
249 |
-
</html>
|
250 |
-
'''
|
251 |
-
|
252 |
-
return render_template_string(html, contacts=contacts)
|
253 |
except Exception as e:
|
254 |
-
print(f"Error
|
255 |
return "Internal Server Error", 500
|
256 |
|
257 |
|
258 |
|
259 |
|
|
|
260 |
|
|
|
|
|
|
|
|
|
261 |
|
|
|
|
|
262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
-
#
|
|
|
|
|
267 |
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
pr2_d = ""
|
275 |
-
pr3_d = ""
|
276 |
|
277 |
-
|
278 |
-
|
279 |
-
# Чтение параметров из GET-запроса
|
280 |
-
name_d = request.args.get('name', '')
|
281 |
-
email_d = request.args.get('email', '')
|
282 |
-
phone_d = request.args.get('phone', '')
|
283 |
-
pr1_d = request.args.get('pr1', '')
|
284 |
-
pr2_d = request.args.get('pr2', '')
|
285 |
-
pr3_d = request.args.get('pr3', '')
|
286 |
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
"phone": phone_d,
|
292 |
-
"first_name": name_d,
|
293 |
-
"addfields": {
|
294 |
-
"pr1": pr1_d,
|
295 |
-
"pr2": pr2_d,
|
296 |
-
"pr3": pr3_d
|
297 |
-
}
|
298 |
-
},
|
299 |
-
"system": {
|
300 |
-
"refresh_if_exists": 1
|
301 |
-
},
|
302 |
-
"session": {
|
303 |
-
"utm_source": "",
|
304 |
-
"utm_medium": "",
|
305 |
-
"utm_content": "",
|
306 |
-
"utm_campaign": "",
|
307 |
-
"utm_group": "",
|
308 |
-
"gcpc": "",
|
309 |
-
"gcao": "",
|
310 |
-
"referer": ""
|
311 |
}
|
312 |
-
|
|
|
|
|
313 |
|
314 |
-
# Конвертация JSON в Base64
|
315 |
-
json_str = json.dumps(json_data)
|
316 |
-
params_d = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
|
317 |
|
318 |
-
# Данные для отправки в теле запроса
|
319 |
-
data = {
|
320 |
-
'key': key_d,
|
321 |
-
'action': action_d,
|
322 |
-
'params': params_d
|
323 |
-
}
|
324 |
|
325 |
-
# Отправка POST-запроса с данными в формате "form-data"
|
326 |
-
response = requests.post(gc_url, data=data)
|
327 |
|
328 |
-
# Возвращаем ответ от тестового адреса
|
329 |
-
return {
|
330 |
-
'status_code': response.status_code,
|
331 |
-
'response_body': response.text
|
332 |
-
}
|
333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
|
|
|
|
|
335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
|
337 |
|
338 |
|
@@ -346,7 +605,6 @@ def gc_db():
|
|
346 |
|
347 |
|
348 |
|
349 |
-
|
350 |
|
351 |
if __name__ == '__main__':
|
352 |
-
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
1 |
+
from flask import Flask, request, render_template_string, render_template, jsonify
|
|
|
2 |
import sqlite3
|
3 |
import os
|
4 |
+
import random
|
5 |
+
import requests
|
6 |
+
import time
|
7 |
+
import re
|
8 |
import json
|
9 |
import base64
|
|
|
|
|
10 |
|
11 |
+
from unidecode import unidecode
|
12 |
+
|
13 |
+
api_key_sys = os.getenv('api_key_sys')
|
14 |
+
|
15 |
gc_url = os.getenv('gc_url')
|
16 |
+
gc_api = os.getenv('gc_api')
|
17 |
+
|
18 |
+
wa_url = os.getenv('wa_url')
|
19 |
+
wa_api_key = os.getenv('wa_api_key')
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
|
|
|
|
25 |
|
|
|
26 |
|
27 |
app = Flask(__name__, template_folder="./")
|
28 |
+
app.config['DEBUG'] = True
|
29 |
+
UPLOAD_FOLDER = 'static'
|
30 |
|
31 |
+
if not os.path.exists(UPLOAD_FOLDER):
|
32 |
+
os.makedirs(UPLOAD_FOLDER)
|
33 |
|
34 |
+
DATABASES = ['data_gc.db', 'data1.db', 'data2.db', 'data3.db', 'data4.db', 'data5.db']
|
35 |
|
36 |
+
def init_db(db_name):
|
37 |
+
conn = sqlite3.connect(db_name)
|
38 |
+
cursor = conn.cursor()
|
39 |
+
cursor.execute('''
|
40 |
+
CREATE TABLE IF NOT EXISTS contacts (
|
41 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
42 |
+
name TEXT NOT NULL,
|
43 |
+
phone TEXT NOT NULL,
|
44 |
+
email TEXT NOT NULL
|
45 |
+
)
|
46 |
+
''')
|
47 |
+
conn.commit()
|
48 |
+
conn.close()
|
49 |
|
50 |
+
for db in DATABASES:
|
51 |
+
init_db(db)
|
52 |
|
53 |
+
def randomize_message(template):
|
54 |
+
def replace_placeholder(match):
|
55 |
+
options = match.group(1).split('|')
|
56 |
+
return random.choice(options)
|
57 |
+
|
58 |
+
return re.sub(r'\{([^}]+)\}', replace_placeholder, template)
|
59 |
+
|
60 |
+
def clean_phone_number(phone):
|
61 |
+
if phone.startswith('+'):
|
62 |
+
return phone[1:]
|
63 |
+
return phone
|
64 |
+
|
65 |
+
def send_message(chat_id, message):
|
66 |
+
#base_url = os.getenv('wa_url')
|
67 |
+
#api_key = os.getenv('wa_api_key')
|
68 |
+
full_url = f"{wa_url}{wa_api_key}"
|
69 |
+
payload = {
|
70 |
+
"chatId": chat_id,
|
71 |
+
"message": message
|
72 |
+
}
|
73 |
+
headers = {
|
74 |
+
'Content-Type': 'application/json'
|
75 |
+
}
|
76 |
+
response = requests.request("POST", full_url, headers=headers, json=payload)
|
77 |
+
try:
|
78 |
+
response_json = response.json()
|
79 |
+
except ValueError:
|
80 |
+
response_json = {"error": "Invalid JSON response"}
|
81 |
+
return response_json
|
82 |
|
83 |
+
def check_and_send_mailings(mesage_db1, clean_db):
|
84 |
+
try:
|
85 |
+
results = []
|
86 |
+
for database in DATABASES:
|
87 |
+
conn = sqlite3.connect(database)
|
88 |
+
cursor = conn.cursor()
|
89 |
+
cursor.execute('SELECT name, phone FROM contacts')
|
90 |
+
contacts = cursor.fetchall()
|
91 |
+
conn.close()
|
92 |
+
|
93 |
+
for contact in contacts:
|
94 |
+
name = contact[0]
|
95 |
+
chat_id = f"{clean_phone_number(contact[1])}@c.us"
|
96 |
+
message = randomize_message(mesage_db1)
|
97 |
+
message = message.replace('[[nemes]]', name) # Подстановка имени
|
98 |
+
send_result = send_message(chat_id, message)
|
99 |
+
results.append({
|
100 |
+
"chat_id": chat_id,
|
101 |
+
"message": message,
|
102 |
+
"result": send_result
|
103 |
+
})
|
104 |
+
|
105 |
+
if clean_db == '1':
|
106 |
+
conn = sqlite3.connect(database)
|
107 |
+
cursor = conn.cursor()
|
108 |
+
cursor.execute('DELETE FROM contacts')
|
109 |
+
conn.commit()
|
110 |
+
conn.close()
|
111 |
+
|
112 |
+
return jsonify({"status": "success", "results": results}), 200
|
113 |
+
except Exception as e:
|
114 |
+
print(f"Error sending mailings: {e}")
|
115 |
+
return jsonify({"status": "error", "message": str(e)}), 500
|
116 |
+
|
117 |
+
#С проверкой sys
|
118 |
+
@app.route('/start_db', methods=['GET'])
|
119 |
+
def start_mailings():
|
120 |
+
mesage_db1 = request.args.get('mesage')
|
121 |
+
clean_db = request.args.get('clean_db')
|
122 |
+
api_sys_control = request.args.get('api_sys')
|
123 |
+
|
124 |
|
125 |
+
if not mesage_db1:
|
126 |
+
return "Parameter 'mesage' is required.", 400
|
|
|
127 |
|
128 |
+
if api_sys_control != api_key_sys:
|
129 |
+
return "EUR 22", 200
|
130 |
|
131 |
+
return check_and_send_mailings(mesage_db1, clean_db)
|
132 |
|
|
|
|
|
133 |
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
@app.route('/add_data_gc', methods=['GET'])
|
139 |
+
def add_data_gc():
|
140 |
+
try:
|
141 |
+
name = request.args.get('name')
|
142 |
+
phone = request.args.get('phone')
|
143 |
+
email = request.args.get('email')
|
144 |
+
api_sys_control = request.args.get('api_sys')
|
145 |
+
|
146 |
+
if not name or not phone or not email:
|
147 |
+
return "Parameters 'name', 'phone', and 'email' are required.", 400
|
148 |
+
|
149 |
+
if api_sys_control != api_key_sys:
|
150 |
+
return "EUR 22", 200
|
151 |
+
|
152 |
+
# Проверка и удаление плюса в начале номера телефона, если он ��сть
|
153 |
+
if phone.startswith('+'):
|
154 |
+
phone = phone[1:]
|
155 |
+
|
156 |
+
conn = sqlite3.connect('data_gc.db')
|
157 |
+
cursor = conn.cursor()
|
158 |
+
cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
|
159 |
+
existing_contact = cursor.fetchone()
|
160 |
+
|
161 |
+
if existing_contact:
|
162 |
+
return f"Contact with phone {phone} or email {email} already exists."
|
163 |
+
|
164 |
+
cursor.execute('INSERT INTO contacts (name, phone, email) VALUES (?, ?, ?)', (name, phone, email))
|
165 |
+
conn.commit()
|
166 |
+
conn.close()
|
167 |
+
|
168 |
+
return f"Contact added: {name} - {phone} - {email}", 200
|
169 |
+
except Exception as e:
|
170 |
+
print(f"Error adding contact: {e}")
|
171 |
+
return "Internal Server Error", 500
|
172 |
+
|
173 |
+
|
174 |
+
@app.route('/add_data_ras', methods=['GET'])
|
175 |
+
def add_contact():
|
176 |
try:
|
177 |
+
name = request.args.get('name')
|
178 |
+
phone = request.args.get('phone')
|
179 |
+
email = request.args.get('email')
|
180 |
+
api_sys_control = request.args.get('api_sys')
|
181 |
+
|
182 |
+
if not name or not phone or not email:
|
183 |
+
return "Parameters 'name', 'phone', and 'email' are required.", 400
|
184 |
+
|
185 |
+
if api_sys_control != api_key_sys:
|
186 |
+
return "EUR 22", 200
|
187 |
+
|
188 |
+
# Проверка и удаление плюса в начале номера телефона, если он есть
|
189 |
+
if phone.startswith('+'):
|
190 |
+
phone = phone[1:]
|
191 |
+
|
192 |
+
conn = sqlite3.connect('data1.db')
|
193 |
cursor = conn.cursor()
|
194 |
+
cursor.execute('INSERT INTO contacts (name, phone, email) VALUES (?, ?, ?)', (name, phone, email))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
conn.commit()
|
196 |
conn.close()
|
197 |
+
|
198 |
+
return f"Contact added: {name} - {phone} - {email}", 200
|
199 |
except Exception as e:
|
200 |
+
print(f"Error adding contact: {e}")
|
201 |
+
return "Internal Server Error", 500
|
202 |
|
203 |
+
@app.route('/data_gc')
|
204 |
+
def show_data_gc():
|
205 |
+
try:
|
206 |
+
api_sys_control = request.args.get('api_sys')
|
207 |
|
208 |
+
if api_sys_control != api_key_sys:
|
209 |
+
return "EUR 22", 200
|
210 |
+
|
211 |
+
conn = sqlite3.connect('data_gc.db')
|
212 |
+
cursor = conn.cursor()
|
213 |
+
cursor.execute('SELECT name, phone, email FROM contacts')
|
214 |
+
contacts = cursor.fetchall()
|
215 |
+
cursor.execute('SELECT COUNT(*) FROM contacts')
|
216 |
+
total_users = cursor.fetchone()[0]
|
217 |
+
conn.close()
|
218 |
+
|
219 |
+
return render_template('data_gc.html', contacts=contacts, total_users=total_users)
|
220 |
+
except Exception as e:
|
221 |
+
print(f"Error showing contacts: {e}")
|
222 |
+
return "Internal Server Error", 500
|
223 |
+
|
224 |
+
|
225 |
+
@app.route('/data_ras')
|
226 |
+
def show_data_ras():
|
227 |
+
try:
|
228 |
+
api_sys_control = request.args.get('api_sys')
|
229 |
+
|
230 |
+
if api_sys_control != api_key_sys:
|
231 |
+
return "EUR 22", 200
|
232 |
+
|
233 |
+
conn = sqlite3.connect('data1.db')
|
234 |
+
cursor = conn.cursor()
|
235 |
+
cursor.execute('SELECT name, phone, email FROM contacts')
|
236 |
+
contacts = cursor.fetchall()
|
237 |
+
cursor.execute('SELECT COUNT(*) FROM contacts')
|
238 |
+
total_users = cursor.fetchone()[0]
|
239 |
+
conn.close()
|
240 |
+
|
241 |
+
return render_template('data_ras.html', contacts=contacts, total_users=total_users)
|
242 |
+
except Exception as e:
|
243 |
+
print(f"Error showing contacts: {e}")
|
244 |
+
return "Internal Server Error", 500
|
245 |
|
246 |
|
|
|
|
|
|
|
247 |
|
248 |
|
|
|
|
|
|
|
249 |
|
250 |
|
251 |
|
|
|
255 |
|
256 |
@app.route('/ver', methods=['GET'])
|
257 |
def veref():
|
258 |
+
api_sys_control = request.args.get('api_sys')
|
259 |
+
if api_sys_control != api_key_sys:
|
260 |
+
return "EUR 22", 200
|
261 |
return render_template('ver.html')
|
262 |
|
263 |
@app.route('/se_mes', methods=['GET'])
|
264 |
def se_mes():
|
265 |
+
api_sys_control = request.args.get('api_sys')
|
266 |
+
if api_sys_control != api_key_sys:
|
267 |
+
return "EUR 22", 200
|
268 |
return render_template('se_mes.html')
|
269 |
|
270 |
@app.route('/se_mes_im', methods=['GET'])
|
271 |
def se_mes_im():
|
272 |
+
api_sys_control = request.args.get('api_sys')
|
273 |
+
if api_sys_control != api_key_sys:
|
274 |
+
return "EUR 22", 200
|
275 |
return render_template('se_mes_im.html')
|
276 |
|
|
|
|
|
277 |
@app.route('/se_mes_ran', methods=['GET'])
|
278 |
def se_mes_ran():
|
279 |
+
api_sys_control = request.args.get('api_sys')
|
280 |
+
if api_sys_control != api_key_sys:
|
281 |
+
return "EUR 22", 200
|
282 |
return render_template('se_mes_ran.html')
|
283 |
|
|
|
|
|
284 |
@app.route('/se_mes_im_ran', methods=['GET'])
|
285 |
def se_mes_im_ran():
|
286 |
+
api_sys_control = request.args.get('api_sys')
|
287 |
+
if api_sys_control != api_key_sys:
|
288 |
+
return "EUR 22", 200
|
289 |
return render_template('se_mes_im_ran.html')
|
290 |
|
|
|
|
|
|
|
|
|
|
|
291 |
@app.route('/se_mes_im2', methods=['GET'])
|
292 |
def se_mes_im2():
|
293 |
+
api_sys_control = request.args.get('api_sys')
|
294 |
+
if api_sys_control != api_key_sys:
|
295 |
+
return "EUR 22", 200
|
296 |
return render_template('se_mes_im2.html')
|
297 |
|
298 |
@app.route('/se_mes_f', methods=['GET'])
|
299 |
def se_mes_f():
|
300 |
+
api_sys_control = request.args.get('api_sys')
|
301 |
+
if api_sys_control != api_key_sys:
|
302 |
+
return "EUR 22", 200
|
303 |
return render_template('se_mes_f.html')
|
304 |
|
305 |
@app.route('/up_gr', methods=['GET'])
|
306 |
def up_gr():
|
307 |
+
api_sys_control = request.args.get('api_sys')
|
308 |
+
if api_sys_control != api_key_sys:
|
309 |
+
return "EUR 22", 200
|
310 |
return render_template('up_gr.html')
|
311 |
|
312 |
@app.route('/up_user_gp', methods=['GET'])
|
313 |
def up_user_gp():
|
314 |
+
api_sys_control = request.args.get('api_sys')
|
315 |
+
if api_sys_control != api_key_sys:
|
316 |
+
return "EUR 22", 200
|
317 |
return render_template('up_user_gp.html')
|
318 |
|
319 |
@app.route('/del_user_gp', methods=['GET'])
|
320 |
def del_user_gp():
|
321 |
+
api_sys_control = request.args.get('api_sys')
|
322 |
+
if api_sys_control != api_key_sys:
|
323 |
+
return "EUR 22", 200
|
324 |
return render_template('del_user_gp.html')
|
325 |
|
326 |
@app.route('/up_ad', methods=['GET'])
|
327 |
def up_ad():
|
328 |
+
api_sys_control = request.args.get('api_sys')
|
329 |
+
if api_sys_control != api_key_sys:
|
330 |
+
return "EUR 22", 200
|
331 |
return render_template('up_ad.html')
|
332 |
|
333 |
@app.route('/del_ad', methods=['GET'])
|
334 |
def del_ad():
|
335 |
+
api_sys_control = request.args.get('api_sys')
|
336 |
+
if api_sys_control != api_key_sys:
|
337 |
+
return "EUR 22", 200
|
338 |
return render_template('del_ad.html')
|
339 |
+
|
340 |
@app.route('/se_opr', methods=['GET'])
|
341 |
def se_opr():
|
342 |
+
api_sys_control = request.args.get('api_sys')
|
343 |
+
if api_sys_control != api_key_sys:
|
344 |
+
return "EUR 22", 200
|
345 |
+
return render_template('se_opr.html')
|
346 |
|
347 |
@app.route('/online', methods=['GET'])
|
348 |
def online():
|
349 |
+
api_sys_control = request.args.get('api_sys')
|
350 |
+
if api_sys_control != api_key_sys:
|
351 |
+
return "EUR 22", 200
|
352 |
return render_template('online.html')
|
353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
|
|
|
|
|
|
|
355 |
|
|
|
|
|
|
|
356 |
|
357 |
|
358 |
|
|
|
360 |
|
361 |
|
362 |
|
363 |
+
|
364 |
+
|
365 |
+
|
366 |
+
|
367 |
+
|
368 |
+
|
369 |
+
|
370 |
+
@app.route('/total_users', methods=['GET'])
|
371 |
+
def total_users():
|
372 |
try:
|
373 |
+
api_sys_control = request.args.get('api_sys')
|
374 |
+
|
375 |
+
if api_sys_control != api_key_sys:
|
376 |
+
return "EUR 22", 200
|
377 |
+
|
378 |
+
total_users_gc = 0
|
379 |
+
total_users_ras = 0
|
380 |
+
|
381 |
+
conn_gc = sqlite3.connect('data_gc.db')
|
382 |
+
cursor_gc = conn_gc.cursor()
|
383 |
+
cursor_gc.execute('SELECT COUNT(*) FROM contacts')
|
384 |
+
total_users_gc = cursor_gc.fetchone()[0]
|
385 |
+
conn_gc.close()
|
386 |
+
|
387 |
+
conn_ras = sqlite3.connect('data1.db')
|
388 |
+
cursor_ras = conn_ras.cursor()
|
389 |
+
cursor_ras.execute('SELECT COUNT(*) FROM contacts')
|
390 |
+
total_users_ras = cursor_ras.fetchone()[0]
|
391 |
+
conn_ras.close()
|
392 |
+
|
393 |
+
return jsonify({
|
394 |
+
"total_users_gc": total_users_gc,
|
395 |
+
"total_users_ras": total_users_ras
|
396 |
+
}), 200
|
397 |
+
except Exception as e:
|
398 |
+
print(f"Error getting total users: {e}")
|
399 |
+
return "Internal Server Error", 500
|
400 |
|
|
|
|
|
401 |
|
402 |
+
|
403 |
+
|
404 |
+
|
405 |
+
|
406 |
+
|
407 |
+
|
408 |
+
@app.route('/all_users_gc', methods=['GET'])
|
409 |
+
def all_users_gc():
|
410 |
+
try:
|
411 |
+
api_sys_control = request.args.get('api_sys')
|
412 |
+
|
413 |
+
if api_sys_control != api_key_sys:
|
414 |
+
return "EUR 22", 200
|
415 |
+
|
416 |
+
conn = sqlite3.connect('data_gc.db')
|
417 |
cursor = conn.cursor()
|
418 |
+
cursor.execute('SELECT name, phone, email FROM contacts')
|
419 |
+
contacts = cursor.fetchall()
|
420 |
conn.close()
|
421 |
|
422 |
+
return jsonify(contacts), 200
|
423 |
except Exception as e:
|
424 |
+
print(f"Error getting all users from data_gc: {e}")
|
425 |
return "Internal Server Error", 500
|
426 |
|
427 |
+
|
428 |
+
|
429 |
+
@app.route('/all_users_ras', methods=['GET'])
|
430 |
+
def all_users_ras():
|
431 |
try:
|
432 |
+
api_sys_control = request.args.get('api_sys')
|
433 |
+
|
434 |
+
if api_sys_control != api_key_sys:
|
435 |
+
return "EUR 22", 200
|
436 |
+
|
437 |
conn = sqlite3.connect('data1.db')
|
438 |
cursor = conn.cursor()
|
439 |
cursor.execute('SELECT name, phone, email FROM contacts')
|
440 |
contacts = cursor.fetchall()
|
441 |
conn.close()
|
442 |
|
443 |
+
return jsonify(contacts), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
except Exception as e:
|
445 |
+
print(f"Error getting all users from data_ras: {e}")
|
446 |
return "Internal Server Error", 500
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
+
|
452 |
|
453 |
+
@app.route('/gc_db_no_email', methods=['GET'])
|
454 |
+
def gc_db_no_email():
|
455 |
+
try:
|
456 |
+
api_sys_control = request.args.get('api_sys')
|
457 |
|
458 |
+
if api_sys_control != api_key_sys:
|
459 |
+
return "EUR 22", 200
|
460 |
|
461 |
+
# Чтение параметров из GET-запроса
|
462 |
+
name_d = request.args.get('name', '')
|
463 |
+
phone_d = request.args.get('phone', '')
|
464 |
+
pr1_d = request.args.get('pr1', '')
|
465 |
+
pr2_d = request.args.get('pr2', '')
|
466 |
+
pr3_d = request.args.get('pr3', '')
|
467 |
|
468 |
+
# Проверка базы данных на наличие email по номеру телефона
|
469 |
+
conn = sqlite3.connect('data_gc.db')
|
470 |
+
cursor = conn.cursor()
|
471 |
+
cursor.execute('SELECT email FROM contacts WHERE phone = ?', (phone_d,))
|
472 |
+
result = cursor.fetchone()
|
473 |
+
email_d = result[0] if result else ''
|
474 |
+
conn.close()
|
475 |
|
476 |
+
# Формирование JSON
|
477 |
+
json_data = {
|
478 |
+
"user": {
|
479 |
+
"email": email_d,
|
480 |
+
"phone": phone_d,
|
481 |
+
"first_name": name_d,
|
482 |
+
"addfields": {
|
483 |
+
"pr1": pr1_d,
|
484 |
+
"pr2": pr2_d,
|
485 |
+
"pr3": pr3_d
|
486 |
+
}
|
487 |
+
},
|
488 |
+
"system": {
|
489 |
+
"refresh_if_exists": 1
|
490 |
+
},
|
491 |
+
"session": {
|
492 |
+
"utm_source": "",
|
493 |
+
"utm_medium": "",
|
494 |
+
"utm_content": "",
|
495 |
+
"utm_campaign": "",
|
496 |
+
"utm_group": "",
|
497 |
+
"gcpc": "",
|
498 |
+
"gcao": "",
|
499 |
+
"referer": ""
|
500 |
+
}
|
501 |
+
}
|
502 |
|
503 |
+
# Конвертация JSON в Base64
|
504 |
+
json_str = json.dumps(json_data)
|
505 |
+
params_d = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
|
506 |
|
507 |
+
# Данные для отправки в теле запроса
|
508 |
+
data = {
|
509 |
+
'key': gc_api,
|
510 |
+
'action': 'add',
|
511 |
+
'params': params_d
|
512 |
+
}
|
|
|
|
|
513 |
|
514 |
+
# Отправка POST-запроса с данными в формате "form-data"
|
515 |
+
response = requests.post(gc_url, data=data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
|
517 |
+
# Возвращаем ответ от тестового адреса
|
518 |
+
return {
|
519 |
+
'status_code': response.status_code,
|
520 |
+
'response_body': response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
}
|
522 |
+
except Exception as e:
|
523 |
+
print(f"Error in gc_db_no_email: {e}")
|
524 |
+
return "Internal Server Error", 500
|
525 |
|
|
|
|
|
|
|
526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
|
|
|
|
|
528 |
|
|
|
|
|
|
|
|
|
|
|
529 |
|
530 |
+
@app.route('/gc_db_email', methods=['GET'])
|
531 |
+
def gc_db_email():
|
532 |
+
try:
|
533 |
+
api_sys_control = request.args.get('api_sys')
|
534 |
+
|
535 |
+
if api_sys_control != api_key_sys:
|
536 |
+
return "EUR 22", 200
|
537 |
+
|
538 |
+
# Чтение параметров из GET-запроса
|
539 |
+
name_d = request.args.get('name', '')
|
540 |
+
email_d = request.args.get('email', '')
|
541 |
+
phone_d = request.args.get('phone', '')
|
542 |
+
pr1_d = request.args.get('pr1', '')
|
543 |
+
pr2_d = request.args.get('pr2', '')
|
544 |
+
pr3_d = request.args.get('pr3', '')
|
545 |
+
|
546 |
+
# Формирование JSON
|
547 |
+
json_data = {
|
548 |
+
"user": {
|
549 |
+
"email": email_d,
|
550 |
+
"phone": phone_d,
|
551 |
+
"first_name": name_d,
|
552 |
+
"addfields": {
|
553 |
+
"pr1": pr1_d,
|
554 |
+
"pr2": pr2_d,
|
555 |
+
"pr3": pr3_d
|
556 |
+
}
|
557 |
+
},
|
558 |
+
"system": {
|
559 |
+
"refresh_if_exists": 1
|
560 |
+
},
|
561 |
+
"session": {
|
562 |
+
"utm_source": "",
|
563 |
+
"utm_medium": "",
|
564 |
+
"utm_content": "",
|
565 |
+
"utm_campaign": "",
|
566 |
+
"utm_group": "",
|
567 |
+
"gcpc": "",
|
568 |
+
"gcao": "",
|
569 |
+
"referer": ""
|
570 |
+
}
|
571 |
+
}
|
572 |
+
|
573 |
+
# Конвертация JSON в Base64
|
574 |
+
json_str = json.dumps(json_data)
|
575 |
+
params_d = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
|
576 |
+
|
577 |
+
# Данные для отправки в теле запроса
|
578 |
+
data = {
|
579 |
+
'key': gc_api,
|
580 |
+
'action': action_d,
|
581 |
+
'params': params_d
|
582 |
+
}
|
583 |
|
584 |
+
# Отправка POST-запроса с данными в формате "form-data"
|
585 |
+
response = requests.post(gc_url, data=data)
|
586 |
|
587 |
+
# Возвращаем ответ от тестового адреса
|
588 |
+
return {
|
589 |
+
'status_code': response.status_code,
|
590 |
+
'response_body': response.text
|
591 |
+
}
|
592 |
+
except Exception as e:
|
593 |
+
print(f"Error in gc_db_email: {e}")
|
594 |
+
return "Internal Server Error", 500
|
595 |
|
596 |
|
597 |
|
|
|
605 |
|
606 |
|
607 |
|
|
|
608 |
|
609 |
if __name__ == '__main__':
|
610 |
+
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|