Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,16 @@ token = os.getenv('token') # Ваш токен
|
|
9 |
api_key = os.getenv('api_key') # Ваш
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
datas = '0'
|
13 |
name = '0'
|
14 |
email = '0'
|
@@ -33,10 +43,7 @@ def send_request():
|
|
33 |
api_token = request.form.get('api_token')
|
34 |
group_id = request.form.get('group_id')
|
35 |
url = f"https://api.notisend.ru/v1/email/lists/{group_id}/parameters"
|
36 |
-
|
37 |
-
'Content-Type': 'application/json',
|
38 |
-
'Authorization': f'Bearer {api_token}'
|
39 |
-
}
|
40 |
response = requests.get(url, headers=headers)
|
41 |
data = response.json()
|
42 |
return jsonify(data)
|
@@ -139,6 +146,34 @@ def save_db():
|
|
139 |
|
140 |
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
|
144 |
|
@@ -161,102 +196,13 @@ def handle_incoming_request():
|
|
161 |
current_hour = current_datetime.hour
|
162 |
|
163 |
if current_day in [0, 4, 5, 6]: # Понедельник, Пятница, Суббота, Воскресенье
|
164 |
-
#
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
"email": email,
|
169 |
-
"unconfirmed": False,
|
170 |
-
"values": [
|
171 |
-
{
|
172 |
-
"parameter_id": 393120,
|
173 |
-
"kind": "string",
|
174 |
-
"list_id": list_id_1,
|
175 |
-
"title": "phone",
|
176 |
-
"value": phone
|
177 |
-
},
|
178 |
-
{
|
179 |
-
"parameter_id": 393119,
|
180 |
-
"kind": "string",
|
181 |
-
"list_id": list_id_1,
|
182 |
-
"title": "name",
|
183 |
-
"value": name
|
184 |
-
}
|
185 |
-
]
|
186 |
-
}
|
187 |
-
headers = {
|
188 |
-
'Authorization': f'Bearer {token}',
|
189 |
-
'Content-Type': 'application/json'
|
190 |
-
}
|
191 |
-
|
192 |
-
# Отправляем первый запрос и сохраняем ответ
|
193 |
-
response_1 = requests.post(f"{base_url}/email/lists/{list_id_1}/recipients", json=data_1, headers=headers)
|
194 |
-
|
195 |
-
# Лист 2
|
196 |
-
data_2 = {
|
197 |
-
"email": email,
|
198 |
-
"unconfirmed": False,
|
199 |
-
"values": [
|
200 |
-
{
|
201 |
-
"parameter_id": 393196,
|
202 |
-
"kind": "string",
|
203 |
-
"list_id": list_id_2,
|
204 |
-
"title": "phone",
|
205 |
-
"value": phone
|
206 |
-
},
|
207 |
-
{
|
208 |
-
"parameter_id": 393195,
|
209 |
-
"kind": "string",
|
210 |
-
"list_id": list_id_2,
|
211 |
-
"title": "name",
|
212 |
-
"value": name
|
213 |
-
}
|
214 |
-
]
|
215 |
-
}
|
216 |
-
|
217 |
-
# Добавляем заголовок для второго запроса
|
218 |
-
headers_2 = {
|
219 |
-
'Authorization': f'Bearer {token}',
|
220 |
-
'Content-Type': 'application/json'
|
221 |
-
}
|
222 |
-
|
223 |
-
# Отправляем второй запрос и сохраняем ответ
|
224 |
-
response_2 = requests.post(f"{base_url}/email/lists/{list_id_2}/recipients", json=data_2, headers=headers_2)
|
225 |
-
|
226 |
-
|
227 |
-
# Лист 3
|
228 |
-
data_3 = {
|
229 |
-
"email": email,
|
230 |
-
"unconfirmed": False,
|
231 |
-
"values": [
|
232 |
-
{
|
233 |
-
"parameter_id": 393198,
|
234 |
-
"kind": "string",
|
235 |
-
"list_id": list_id_3,
|
236 |
-
"title": "phone",
|
237 |
-
"value": phone
|
238 |
-
},
|
239 |
-
{
|
240 |
-
"parameter_id": 393197,
|
241 |
-
"kind": "string",
|
242 |
-
"list_id": list_id_3,
|
243 |
-
"title": "name",
|
244 |
-
"value": name
|
245 |
-
}
|
246 |
-
]
|
247 |
-
}
|
248 |
-
|
249 |
-
# Добавляем заголовок для второго запроса
|
250 |
-
headers_3 = {
|
251 |
-
'Authorization': f'Bearer {token}',
|
252 |
-
'Content-Type': 'application/json'
|
253 |
-
}
|
254 |
-
|
255 |
-
# Отправляем второй запрос и сохраняем ответ
|
256 |
-
response_3 = requests.post(f"{base_url}/email/lists/{list_id_3}/recipients", json=data_3, headers=headers_3)
|
257 |
|
258 |
# Возвращаем список ответов
|
259 |
-
return {'responses': [response_1
|
260 |
|
261 |
elif current_day == 1: # Вторник
|
262 |
if current_hour < 19:
|
@@ -267,7 +213,7 @@ def handle_incoming_request():
|
|
267 |
|
268 |
|
269 |
|
270 |
-
# Лист 1
|
271 |
data_1 = {
|
272 |
"email": email,
|
273 |
"unconfirmed": False,
|
@@ -296,7 +242,34 @@ def handle_incoming_request():
|
|
296 |
# Отправляем первый запрос и сохраняем ответ
|
297 |
response_1 = requests.post(f"{base_url}/email/lists/{list_id_1}/recipients", json=data_1, headers=headers)
|
298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
|
|
|
|
|
300 |
|
301 |
|
302 |
|
|
|
9 |
api_key = os.getenv('api_key') # Ваш
|
10 |
|
11 |
|
12 |
+
|
13 |
+
headers = {
|
14 |
+
'Authorization': f'Bearer {token}',
|
15 |
+
'Content-Type': 'application/json'
|
16 |
+
}
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
datas = '0'
|
23 |
name = '0'
|
24 |
email = '0'
|
|
|
43 |
api_token = request.form.get('api_token')
|
44 |
group_id = request.form.get('group_id')
|
45 |
url = f"https://api.notisend.ru/v1/email/lists/{group_id}/parameters"
|
46 |
+
|
|
|
|
|
|
|
47 |
response = requests.get(url, headers=headers)
|
48 |
data = response.json()
|
49 |
return jsonify(data)
|
|
|
146 |
|
147 |
|
148 |
|
149 |
+
def send_request(list_id, email, phone, name, param_phone, param_name):
|
150 |
+
"""Функция для отправки запроса на сервер."""
|
151 |
+
data = {
|
152 |
+
"email": email,
|
153 |
+
"unconfirmed": False,
|
154 |
+
"values": [
|
155 |
+
{
|
156 |
+
"parameter_id": param_phone,
|
157 |
+
"kind": "string",
|
158 |
+
"list_id": list_id,
|
159 |
+
"title": "phone",
|
160 |
+
"value": phone
|
161 |
+
},
|
162 |
+
{
|
163 |
+
"parameter_id": param_name,
|
164 |
+
"kind": "string",
|
165 |
+
"list_id": list_id,
|
166 |
+
"title": "name",
|
167 |
+
"value": name
|
168 |
+
}
|
169 |
+
]
|
170 |
+
}
|
171 |
+
headers = {
|
172 |
+
'Authorization': f'Bearer {token}',
|
173 |
+
'Content-Type': 'application/json'
|
174 |
+
}
|
175 |
+
response = requests.post(f"{base_url}/email/lists/{list_id}/recipients", json=data, headers=headers)
|
176 |
+
return response.json()
|
177 |
|
178 |
|
179 |
|
|
|
196 |
current_hour = current_datetime.hour
|
197 |
|
198 |
if current_day in [0, 4, 5, 6]: # Понедельник, Пятница, Суббота, Воскресенье
|
199 |
+
# Отправляем запросы в листы подряд
|
200 |
+
response_1 = send_request(list_id_1, email, phone, name, 393120, 393119)
|
201 |
+
response_2 = send_request(list_id_2, email, phone, name, 393196, 393195)
|
202 |
+
response_3 = send_request(list_id_3, email, phone, name, 393198, 393197)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
# Возвращаем список ответов
|
205 |
+
return {'responses': [response_1, response_2, response_3]}
|
206 |
|
207 |
elif current_day == 1: # Вторник
|
208 |
if current_hour < 19:
|
|
|
213 |
|
214 |
|
215 |
|
216 |
+
# Вторник - Утро - Лист 1
|
217 |
data_1 = {
|
218 |
"email": email,
|
219 |
"unconfirmed": False,
|
|
|
242 |
# Отправляем первый запрос и сохраняем ответ
|
243 |
response_1 = requests.post(f"{base_url}/email/lists/{list_id_1}/recipients", json=data_1, headers=headers)
|
244 |
|
245 |
+
# Вторник - Утро - Лист 2
|
246 |
+
data_1 = {
|
247 |
+
"email": email,
|
248 |
+
"unconfirmed": False,
|
249 |
+
"values": [
|
250 |
+
{
|
251 |
+
"parameter_id": 393120,
|
252 |
+
"kind": "string",
|
253 |
+
"list_id": list_id_2,
|
254 |
+
"title": "phone",
|
255 |
+
"value": phone
|
256 |
+
},
|
257 |
+
{
|
258 |
+
"parameter_id": 393119,
|
259 |
+
"kind": "string",
|
260 |
+
"list_id": list_id_2,
|
261 |
+
"title": "name",
|
262 |
+
"value": name
|
263 |
+
}
|
264 |
+
]
|
265 |
+
}
|
266 |
+
headers = {
|
267 |
+
'Authorization': f'Bearer {token}',
|
268 |
+
'Content-Type': 'application/json'
|
269 |
+
}
|
270 |
|
271 |
+
# Отправляем первый запрос и сохраняем ответ
|
272 |
+
response_2 = requests.post(f"{base_url}/email/lists/{list_id_1}/recipients", json=data_1, headers=headers)
|
273 |
|
274 |
|
275 |
|