Update app.py
Browse files
app.py
CHANGED
|
@@ -85,25 +85,39 @@ for db in DATABASES:
|
|
| 85 |
|
| 86 |
|
| 87 |
# Флаг выполнения кода
|
|
|
|
| 88 |
code_executed = False
|
| 89 |
|
| 90 |
def fetch(url):
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
def send_notification(url, data):
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
def send_requests():
|
| 99 |
global code_executed
|
|
|
|
| 100 |
|
| 101 |
if start_up == '1' and not code_executed:
|
| 102 |
try:
|
| 103 |
# Первый запрос
|
| 104 |
url_template = f"{gc_url_gru}/{id_gru}/users?key={gc_api}&created_at[from]={date_from}&status={status}"
|
| 105 |
data = fetch(url_template)
|
| 106 |
-
if data.get("success"):
|
| 107 |
export_id = data.get("info", {}).get("export_id", "")
|
| 108 |
print("Export ID:", export_id)
|
| 109 |
|
|
@@ -118,7 +132,7 @@ def send_requests():
|
|
| 118 |
|
| 119 |
code_executed = True # Устанавливаем флаг выполнения кода
|
| 120 |
else:
|
| 121 |
-
raise Exception(f"Ошибка в ответе от сервера: {data.get('error_message')}")
|
| 122 |
except Exception as e:
|
| 123 |
print(f"Ошибка: {e}")
|
| 124 |
else:
|
|
|
|
| 85 |
|
| 86 |
|
| 87 |
# Флаг выполнения кода
|
| 88 |
+
|
| 89 |
code_executed = False
|
| 90 |
|
| 91 |
def fetch(url):
|
| 92 |
+
try:
|
| 93 |
+
response = requests.get(url)
|
| 94 |
+
response.raise_for_status()
|
| 95 |
+
print(f"GET запрос к {url} выполнен успешно.")
|
| 96 |
+
return response.json()
|
| 97 |
+
except requests.RequestException as e:
|
| 98 |
+
print(f"Ошибка при выполнении GET запроса к {url}: {e}")
|
| 99 |
+
return None
|
| 100 |
|
| 101 |
def send_notification(url, data):
|
| 102 |
+
try:
|
| 103 |
+
response = requests.post(url, json=data)
|
| 104 |
+
response.raise_for_status()
|
| 105 |
+
print(f"POST запрос к {url} выполнен успешно.")
|
| 106 |
+
return response.json()
|
| 107 |
+
except requests.RequestException as e:
|
| 108 |
+
print(f"Ошибка при выполнении POST запроса к {url}: {e}")
|
| 109 |
+
return None
|
| 110 |
|
| 111 |
def send_requests():
|
| 112 |
global code_executed
|
| 113 |
+
print(f"Функция send_requests вызвана. start_up: {start_up}, code_executed: {code_executed}")
|
| 114 |
|
| 115 |
if start_up == '1' and not code_executed:
|
| 116 |
try:
|
| 117 |
# Первый запрос
|
| 118 |
url_template = f"{gc_url_gru}/{id_gru}/users?key={gc_api}&created_at[from]={date_from}&status={status}"
|
| 119 |
data = fetch(url_template)
|
| 120 |
+
if data and data.get("success"):
|
| 121 |
export_id = data.get("info", {}).get("export_id", "")
|
| 122 |
print("Export ID:", export_id)
|
| 123 |
|
|
|
|
| 132 |
|
| 133 |
code_executed = True # Устанавливаем флаг выполнения кода
|
| 134 |
else:
|
| 135 |
+
raise Exception(f"Ошибка в ответе от сервера: {data.get('error_message') if data else 'Нет данных'}")
|
| 136 |
except Exception as e:
|
| 137 |
print(f"Ошибка: {e}")
|
| 138 |
else:
|