Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,10 +93,7 @@ for db in DATABASES:
|
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
-
#
|
| 97 |
-
|
| 98 |
-
code_executed = False
|
| 99 |
-
|
| 100 |
def fetch(url):
|
| 101 |
try:
|
| 102 |
response = requests.get(url)
|
|
@@ -117,8 +114,9 @@ def send_notification(url, data):
|
|
| 117 |
print(f"Ошибка при выполнении POST запроса к {url}: {e}")
|
| 118 |
return None
|
| 119 |
|
|
|
|
| 120 |
def send_requests():
|
| 121 |
-
global code_executed
|
| 122 |
print(f"Функция send_requests вызвана. start_up: {start_up}, code_executed: {code_executed}")
|
| 123 |
|
| 124 |
if start_up == '1' and not code_executed:
|
|
@@ -147,35 +145,8 @@ def send_requests():
|
|
| 147 |
else:
|
| 148 |
print("Системная переменная start_up не равна '1' или код уже выполнялся.")
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
def fetch(url):
|
| 175 |
-
response = requests.get(url)
|
| 176 |
-
return response.json()
|
| 177 |
-
|
| 178 |
-
def send_second_request():
|
| 179 |
# Формирование URL для второго запроса
|
| 180 |
export_url_template = f"{gc_url_export}/{export_id}?key={gc_api}"
|
| 181 |
data = fetch(export_url_template)
|
|
@@ -185,12 +156,11 @@ def send_second_request():
|
|
| 185 |
else:
|
| 186 |
raise Exception(f"Ошибка при выполнении второго запроса по export_id, статус код: {data.get('status_code')}")
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
@app.route('/export_user', methods=['GET'])
|
| 191 |
def export_user():
|
| 192 |
try:
|
| 193 |
-
response_data = send_second_request()
|
| 194 |
return json.dumps(response_data)
|
| 195 |
except Exception as e:
|
| 196 |
return json.dumps({"error": str(e)})
|
|
@@ -212,6 +182,7 @@ def export_user():
|
|
| 212 |
|
| 213 |
|
| 214 |
|
|
|
|
| 215 |
def load_data_from_json():
|
| 216 |
data = json.loads(json_data)
|
| 217 |
items = data['info']['items']
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
+
# Функции для выполнения HTTP запросов
|
|
|
|
|
|
|
|
|
|
| 97 |
def fetch(url):
|
| 98 |
try:
|
| 99 |
response = requests.get(url)
|
|
|
|
| 114 |
print(f"Ошибка при выполнении POST запроса к {url}: {e}")
|
| 115 |
return None
|
| 116 |
|
| 117 |
+
# Основная функция для отправки запросов
|
| 118 |
def send_requests():
|
| 119 |
+
global code_executed, export_id
|
| 120 |
print(f"Функция send_requests вызвана. start_up: {start_up}, code_executed: {code_executed}")
|
| 121 |
|
| 122 |
if start_up == '1' and not code_executed:
|
|
|
|
| 145 |
else:
|
| 146 |
print("Системная переменная start_up не равна '1' или код уже выполнялся.")
|
| 147 |
|
| 148 |
+
# Функция для отправки второго запроса
|
| 149 |
+
def send_second_request(export_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
# Формирование URL для второго запроса
|
| 151 |
export_url_template = f"{gc_url_export}/{export_id}?key={gc_api}"
|
| 152 |
data = fetch(export_url_template)
|
|
|
|
| 156 |
else:
|
| 157 |
raise Exception(f"Ошибка при выполнении второго запроса по export_id, статус код: {data.get('status_code')}")
|
| 158 |
|
| 159 |
+
# Маршрут для экспорта пользователя
|
|
|
|
| 160 |
@app.route('/export_user', methods=['GET'])
|
| 161 |
def export_user():
|
| 162 |
try:
|
| 163 |
+
response_data = send_second_request(export_id)
|
| 164 |
return json.dumps(response_data)
|
| 165 |
except Exception as e:
|
| 166 |
return json.dumps({"error": str(e)})
|
|
|
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
+
|
| 186 |
def load_data_from_json():
|
| 187 |
data = json.loads(json_data)
|
| 188 |
items = data['info']['items']
|