Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,12 +39,12 @@ ALLOWED_ORIGIN = "https://diamonik7777-up-fail.hf.space"
|
|
39 |
|
40 |
|
41 |
# Замените на ваш реальный ключ VK
|
42 |
-
|
43 |
|
44 |
|
45 |
|
46 |
# Замените на ваш реальный access_token СЕНДЛЕРА
|
47 |
-
|
48 |
|
49 |
import logging
|
50 |
|
@@ -58,9 +58,9 @@ curator_on_off = "0" # Глобальная переменная для упр
|
|
58 |
curators = ["Anna", "Ekaterina", "Ivan", "Maria", "Sergey", "Olga", "Alex", "Natalia", "Dmitry", "Elena"]
|
59 |
|
60 |
# Глобальная переменная для
|
61 |
-
|
62 |
wa_api_key = os.getenv('wa_api_key')
|
63 |
-
|
64 |
ws_url_mes = "/sendMessage/"
|
65 |
ws_url_ver = "/checkWhatsapp/"
|
66 |
|
@@ -93,7 +93,8 @@ if not os.path.exists(HTML_FOLDER):
|
|
93 |
|
94 |
|
95 |
DATABASES = ['data_gc.db', 'site_data.db', 'ws_data.db', 'vk_data.db', 'tg_data.db', 'gk_data.db']
|
96 |
-
|
|
|
97 |
|
98 |
def init_db(db_name):
|
99 |
conn = sqlite3.connect(db_name)
|
@@ -141,116 +142,110 @@ def init_db(db_name):
|
|
141 |
conn.commit()
|
142 |
conn.close()
|
143 |
|
144 |
-
def init_settings_db():
|
145 |
-
conn = sqlite3.connect(SETTINGS_DB)
|
146 |
-
cursor = conn.cursor()
|
147 |
-
cursor.execute('''
|
148 |
-
CREATE TABLE IF NOT EXISTS settings (
|
149 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
150 |
-
api_key_auth TEXT,
|
151 |
-
crypto_key_auth TEXT,
|
152 |
-
crypto_key_url TEXT,
|
153 |
-
vk_api_key TEXT,
|
154 |
-
senler_token TEXT,
|
155 |
-
wa_ak TEXT,
|
156 |
-
wa_api_key TEXT,
|
157 |
-
curators TEXT,
|
158 |
-
call_api_key TEXT
|
159 |
-
)
|
160 |
-
''')
|
161 |
-
conn.commit()
|
162 |
-
conn.close()
|
163 |
-
|
164 |
for db in DATABASES:
|
165 |
init_db(db)
|
166 |
|
167 |
-
init_settings_db()
|
168 |
-
|
169 |
-
def load_settings():
|
170 |
-
conn = sqlite3.connect(SETTINGS_DB)
|
171 |
-
cursor = conn.cursor()
|
172 |
-
cursor.execute('SELECT * FROM settings')
|
173 |
-
settings = cursor.fetchone()
|
174 |
-
conn.close()
|
175 |
-
if settings is None:
|
176 |
-
return {
|
177 |
-
'api_key_auth': '',
|
178 |
-
'crypto_key_auth': '',
|
179 |
-
'crypto_key_url': '',
|
180 |
-
'vk_api_key': '',
|
181 |
-
'senler_token': '',
|
182 |
-
'wa_ak': '',
|
183 |
-
'wa_api_key': '',
|
184 |
-
'curators': '',
|
185 |
-
'call_api_key': ''
|
186 |
-
}
|
187 |
-
return {
|
188 |
-
'api_key_auth': settings[1],
|
189 |
-
'crypto_key_auth': settings[2],
|
190 |
-
'crypto_key_url': settings[3],
|
191 |
-
'vk_api_key': settings[4],
|
192 |
-
'senler_token': settings[5],
|
193 |
-
'wa_ak': settings[6],
|
194 |
-
'wa_api_key': settings[7],
|
195 |
-
'curators': settings[8],
|
196 |
-
'call_api_key': settings[9]
|
197 |
-
}
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
-
conn = sqlite3.connect(SETTINGS_DB)
|
211 |
-
cursor = conn.cursor()
|
212 |
|
213 |
-
# Выводим каждое значение перед записью в базу данных
|
214 |
-
for key, value in settings_dict.items():
|
215 |
-
print(f"Extracted {key}: {value}")
|
216 |
|
217 |
-
cursor.execute('''
|
218 |
-
INSERT OR REPLACE INTO settings (
|
219 |
-
api_key_auth, crypto_key_auth, crypto_key_url, vk_api_key, senler_token,
|
220 |
-
wa_ak, wa_api_key, curators, call_api_key
|
221 |
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
222 |
-
''', (
|
223 |
-
settings_dict.get('api_key_auth', ''),
|
224 |
-
settings_dict.get('crypto_key_auth', ''),
|
225 |
-
settings_dict.get('crypto_key_url', ''),
|
226 |
-
settings_dict.get('vk_api_key', ''),
|
227 |
-
settings_dict.get('senler_token', ''),
|
228 |
-
settings_dict.get('wa_ak', ''),
|
229 |
-
settings_dict.get('wa_api_key', ''),
|
230 |
-
settings_dict.get('curators', ''),
|
231 |
-
settings_dict.get('call_api_key', '')
|
232 |
-
))
|
233 |
-
conn.commit()
|
234 |
-
conn.close()
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
'crypto_key_auth': settings[2],
|
246 |
-
'crypto_key_url': settings[3],
|
247 |
-
'vk_api_key': settings[4],
|
248 |
-
'senler_token': settings[5],
|
249 |
-
'wa_ak': settings[6],
|
250 |
-
'wa_api_key': settings[7],
|
251 |
-
'curators': settings[8],
|
252 |
-
'call_api_key': settings[9]
|
253 |
-
})
|
254 |
|
255 |
@app.route('/load_settings', methods=['POST'])
|
256 |
def get_settings():
|
@@ -258,11 +253,9 @@ def get_settings():
|
|
258 |
client_api_key_sys = request.json.get('api_key_sys')
|
259 |
|
260 |
# Проверка ключа авторизации
|
261 |
-
if client_api_key_sys !=
|
262 |
return jsonify({"error": "Unauthorized access"}), 403
|
263 |
|
264 |
-
# Загружаем настройки из базы данных
|
265 |
-
settings = load_settings()
|
266 |
return jsonify(settings)
|
267 |
|
268 |
@app.route('/save_settings', methods=['POST'])
|
@@ -271,13 +264,11 @@ def save_settings_route():
|
|
271 |
client_api_key_sys = request.json.get('api_key_sys')
|
272 |
|
273 |
# Проверка ключа авторизации
|
274 |
-
if client_api_key_sys !=
|
275 |
return jsonify({"error": "Unauthorized access"}), 403
|
276 |
|
277 |
data = request.json.get('data', {})
|
278 |
if data:
|
279 |
-
# Выводим полученные данные в консоль сервера
|
280 |
-
print("Received data from page:", data)
|
281 |
save_settings(data)
|
282 |
return jsonify({'status': 'success'})
|
283 |
else:
|
@@ -293,6 +284,7 @@ def index_set():
|
|
293 |
|
294 |
|
295 |
|
|
|
296 |
mapping_template = {
|
297 |
"username": "name",
|
298 |
"phone": "phone",
|
|
|
39 |
|
40 |
|
41 |
# Замените на ваш реальный ключ VK
|
42 |
+
vk_api_key = os.getenv('vk_api_key')
|
43 |
|
44 |
|
45 |
|
46 |
# Замените на ваш реальный access_token СЕНДЛЕРА
|
47 |
+
senler_token = os.getenv('senler_token')
|
48 |
|
49 |
import logging
|
50 |
|
|
|
58 |
curators = ["Anna", "Ekaterina", "Ivan", "Maria", "Sergey", "Olga", "Alex", "Natalia", "Dmitry", "Elena"]
|
59 |
|
60 |
# Глобальная переменная для
|
61 |
+
wa_url = os.getenv('wa_url')
|
62 |
wa_api_key = os.getenv('wa_api_key')
|
63 |
+
wa_ak = os.getenv('ws_ak')
|
64 |
ws_url_mes = "/sendMessage/"
|
65 |
ws_url_ver = "/checkWhatsapp/"
|
66 |
|
|
|
93 |
|
94 |
|
95 |
DATABASES = ['data_gc.db', 'site_data.db', 'ws_data.db', 'vk_data.db', 'tg_data.db', 'gk_data.db']
|
96 |
+
|
97 |
+
|
98 |
|
99 |
def init_db(db_name):
|
100 |
conn = sqlite3.connect(db_name)
|
|
|
142 |
conn.commit()
|
143 |
conn.close()
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
for db in DATABASES:
|
146 |
init_db(db)
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
+
DATABASE_NEW = 'data_gc.db'
|
150 |
+
|
151 |
+
|
152 |
+
# Переменная для хранения IP-адреса сервера
|
153 |
+
server_ip = None
|
154 |
+
|
155 |
+
def get_ip_address():
|
156 |
+
global server_ip
|
157 |
+
if server_ip is None:
|
158 |
+
# Определяем IP-адрес сервера
|
159 |
+
hostname = socket.gethostname()
|
160 |
+
server_ip = socket.gethostbyname(hostname)
|
161 |
+
return server_ip
|
162 |
+
|
163 |
+
@app.route('/ip')
|
164 |
+
def index():
|
165 |
+
# Получаем IP-адрес и порт
|
166 |
+
ip_address = get_ip_address()
|
167 |
+
port = int(os.environ.get('PORT', 7860)) # Порт по умолчанию 7860
|
168 |
+
# Формируем HTML-страницу
|
169 |
+
html = f"""
|
170 |
+
<html>
|
171 |
+
<head>
|
172 |
+
<title>Server Info</title>
|
173 |
+
</head>
|
174 |
+
<body>
|
175 |
+
<h1>Server Information</h1>
|
176 |
+
<p>IP Address: {ip_address}</p>
|
177 |
+
<p>Port: {port}</p>
|
178 |
+
</body>
|
179 |
+
</html>
|
180 |
+
"""
|
181 |
+
return render_template_string(html)
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
+
|
186 |
+
|
187 |
+
# Глобальные переменные для хранения настроек
|
188 |
+
api_key_auth = ''
|
189 |
+
crypto_key_auth = ''
|
190 |
+
crypto_key_url = ''
|
191 |
+
vk_api_key_ser = ''
|
192 |
+
senler_token_ser = ''
|
193 |
+
wa_ak_ser = ''
|
194 |
+
wa_api_key_ser = ''
|
195 |
+
curators_ser = ''
|
196 |
+
call_api_key_ser = ''
|
197 |
+
|
198 |
+
# Пример данных настроек
|
199 |
+
settings = {
|
200 |
+
'api_key_auth': 'api_key_auth_setting',
|
201 |
+
'crypto_key_auth': 'crypto_key_auth_setting',
|
202 |
+
'crypto_key_url': 'crypto_key_url_setting',
|
203 |
+
'vk_api_key': 'vk_api_key_setting',
|
204 |
+
'senler_token': 'senler_token_setting',
|
205 |
+
'wa_ak': 'wa_ak_setting',
|
206 |
+
'wa_api_key': 'wa_api_key_setting',
|
207 |
+
'curators': 'curators_setting',
|
208 |
+
'call_api_key': 'call_api_key_setting'
|
209 |
+
}
|
210 |
|
211 |
+
def update_global_variables_from_settings():
|
212 |
+
global api_key_auth, crypto_key_auth, crypto_key_url, vk_api_key_ser, senler_token_ser, wa_ak_ser, wa_api_key_ser, curators_ser, call_api_key_ser
|
213 |
+
|
214 |
+
# Обновляем глобальные переменные из массива settings
|
215 |
+
api_key_auth = settings.get('api_key_auth', '')
|
216 |
+
crypto_key_auth = settings.get('crypto_key_auth', '')
|
217 |
+
crypto_key_url = settings.get('crypto_key_url', '')
|
218 |
+
vk_api_key_ser = settings.get('vk_api_key', '')
|
219 |
+
senler_token_ser = settings.get('senler_token', '')
|
220 |
+
wa_ak_ser = settings.get('wa_ak', '')
|
221 |
+
wa_api_key_ser = settings.get('wa_api_key', '')
|
222 |
+
curators_ser = settings.get('curators', '')
|
223 |
+
call_api_key_ser = settings.get('call_api_key', '')
|
224 |
+
|
225 |
+
# Выводим значения в консоль сервера
|
226 |
+
print("Обновленные глобальные переменные:")
|
227 |
+
print(f"api_key_auth: {api_key_auth}")
|
228 |
+
print(f"crypto_key_auth: {crypto_key_auth}")
|
229 |
+
print(f"crypto_key_url: {crypto_key_url}")
|
230 |
+
print(f"vk_api_key_ser: {vk_api_key_ser}")
|
231 |
+
print(f"senler_token_ser: {senler_token_ser}")
|
232 |
+
print(f"wa_ak_ser: {wa_ak_ser}")
|
233 |
+
print(f"wa_api_key_ser: {wa_api_key_ser}")
|
234 |
+
print(f"curators_ser: {curators_ser}")
|
235 |
+
print(f"call_api_key_ser: {call_api_key_ser}")
|
236 |
|
|
|
|
|
237 |
|
|
|
|
|
|
|
238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
+
def save_settings(settings_dict):
|
241 |
+
global settings
|
242 |
+
|
243 |
+
# Обновляем глобальный словарь settings
|
244 |
+
for key, value in settings_dict.items():
|
245 |
+
if value is not None and key != 'api_key_sys':
|
246 |
+
settings[key] = value
|
247 |
+
|
248 |
+
update_global_variables_from_settings()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
@app.route('/load_settings', methods=['POST'])
|
251 |
def get_settings():
|
|
|
253 |
client_api_key_sys = request.json.get('api_key_sys')
|
254 |
|
255 |
# Проверка ключа авторизации
|
256 |
+
if client_api_key_sys != api_key_sys:
|
257 |
return jsonify({"error": "Unauthorized access"}), 403
|
258 |
|
|
|
|
|
259 |
return jsonify(settings)
|
260 |
|
261 |
@app.route('/save_settings', methods=['POST'])
|
|
|
264 |
client_api_key_sys = request.json.get('api_key_sys')
|
265 |
|
266 |
# Проверка ключа авторизации
|
267 |
+
if client_api_key_sys != api_key_sys:
|
268 |
return jsonify({"error": "Unauthorized access"}), 403
|
269 |
|
270 |
data = request.json.get('data', {})
|
271 |
if data:
|
|
|
|
|
272 |
save_settings(data)
|
273 |
return jsonify({'status': 'success'})
|
274 |
else:
|
|
|
284 |
|
285 |
|
286 |
|
287 |
+
|
288 |
mapping_template = {
|
289 |
"username": "name",
|
290 |
"phone": "phone",
|