DmitrMakeev commited on
Commit
d097f3e
·
verified ·
1 Parent(s): 843fdb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -143
app.py CHANGED
@@ -135,231 +135,117 @@ def save_db():
135
 
136
 
137
 
138
- # Здесь должно быть определение переменных base_url и token для Notisend API
139
-
140
  @app.route('/save_pl', methods=['POST'])
141
  def save_pl():
142
  list_id1 = 560768
143
  list_id2 = 560832
144
- list_id3 = 560833
 
145
  data = request.json
146
  name = data.get('name')
147
  email = data.get('email')
148
  phone = data.get('phone')
149
 
150
- # Определяем текущий день недели (0 - понедельник, 1 - вторник, ..., 6 - воскресенье)
151
  current_day = datetime.datetime.today().weekday()
152
 
153
  urls = []
154
 
155
- # Понедельник, пятница, суббота, воскресенье
156
  if current_day in [0, 4, 5, 6]:
157
  urls = [
158
  (f"{base_url}/email/lists/{list_id1}/recipients_mon_fri_sat_sun", {
159
  "email": email,
160
  "unconfirmed": True,
161
  "values": [
162
- {
163
- "parameter_id": 393120,
164
- "kind": "string",
165
- "list_id": list_id1,
166
- "title": "phone",
167
- "value": phone
168
- },
169
- {
170
- "parameter_id": 393119,
171
- "kind": "string",
172
- "list_id": list_id1,
173
- "title": "name",
174
- "value": name
175
- }
176
  ]
177
  }),
178
  (f"{base_url}/email/lists/{list_id2}/recipients_mon_fri_sat_sun", {
179
  "email": email,
180
  "unconfirmed": True,
181
  "values": [
182
- {
183
- "parameter_id": 393196,
184
- "kind": "string",
185
- "list_id": list_id2,
186
- "title": "phone",
187
- "value": phone
188
- },
189
- {
190
- "parameter_id": 393195,
191
- "kind": "string",
192
- "list_id": list_id2,
193
- "title": "name",
194
- "value": name
195
- }
196
  ]
197
  }),
198
  (f"{base_url}/email/lists/{list_id3}/recipients_mon_fri_sat_sun", {
199
  "email": email,
200
  "unconfirmed": True,
201
  "values": [
202
- {
203
- "parameter_id": 393198,
204
- "kind": "string",
205
- "list_id": list_id3,
206
- "title": "phone",
207
- "value": phone
208
- },
209
- {
210
- "parameter_id": 393197,
211
- "kind": "string",
212
- "list_id": list_id3,
213
- "title": "name",
214
- "value": name
215
- }
216
  ]
217
  })
218
  ]
219
- # Вторник
220
  elif current_day == 1:
221
  current_time = datetime.datetime.now().time()
222
- if current_time < datetime.time(19, 0): # Утро до 19:00
223
  urls = [
224
  (f"{base_url}/email/lists/{list_id1}/recipients_tue_morning", {
225
  "email": email,
226
  "unconfirmed": True,
227
  "values": [
228
- {
229
- "parameter_id": 393120,
230
- "kind": "string",
231
- "list_id": list_id1,
232
- "title": "phone",
233
- "value": phone
234
- },
235
- {
236
- "parameter_id": 393119,
237
- "kind": "string",
238
- "list_id": list_id1,
239
- "title": "name",
240
- "value": name
241
- }
242
  ]
243
  })
244
  ]
245
- else: # Вечер после 19:00
246
  urls = [
247
  (f"{base_url}/email/lists/{list_id1}/recipients_tue_evening", {
248
  "email": email,
249
  "unconfirmed": False,
250
  "values": [
251
- {
252
- "parameter_id": 393120,
253
- "kind": "string",
254
- "list_id": list_id1,
255
- "title": "phone",
256
- "value": phone
257
- },
258
- {
259
- "parameter_id": 393119,
260
- "kind": "string",
261
- "list_id": list_id1,
262
- "title": "name",
263
- "value": name
264
- }
265
  ]
266
  })
267
  ]
268
- # Среда
269
  elif current_day == 2:
270
  current_time = datetime.datetime.now().time()
271
- if current_time < datetime.time(19, 0): # Утро до 19:00
272
  urls = [
273
  (f"{base_url}/email/lists/{list_id1}/recipients_wed_morning", {
274
  "email": email,
275
  "unconfirmed": True,
276
  "values": [
277
- {
278
- "parameter_id": 393120,
279
- "kind": "string",
280
- "list_id": list_id1,
281
- "title": "phone",
282
- "value": phone
283
- },
284
- {
285
- "parameter_id": 393119,
286
- "kind": "string",
287
- "list_id": list_id1,
288
- "title": "name",
289
- "value": name
290
- }
291
  ]
292
  })
293
  ]
294
- else: # Вечер после 19:00
295
  urls = [
296
  (f"{base_url}/email/lists/{list_id1}/recipients_wed_evening", {
297
  "email": email,
298
  "unconfirmed": False,
299
  "values": [
300
- {
301
- "parameter_id": 393120,
302
- "kind": "string",
303
- "list_id": list_id1,
304
- "title": "phone",
305
- "value": phone
306
- },
307
- {
308
- "parameter_id": 393119,
309
- "kind": "string",
310
- "list_id": list_id1,
311
- "title": "name",
312
- "value": name
313
- }
314
  ]
315
  })
316
  ]
317
- # Четверг
318
  elif current_day == 3:
319
  current_time = datetime.datetime.now().time()
320
- if current_time < datetime.time(19, 0): # Утро до 19:00
321
  urls = [
322
  (f"{base_url}/email/lists/{list_id1}/recipients_thu_morning", {
323
  "email": email,
324
  "unconfirmed": True,
325
  "values": [
326
- {
327
- "parameter_id": 393120,
328
- "kind": "string",
329
- "list_id": list_id1,
330
- "title": "phone",
331
- "value": phone
332
- },
333
- {
334
- "parameter_id": 393119,
335
- "kind": "string",
336
- "list_id": list_id1,
337
- "title": "name",
338
- "value": name
339
- }
340
  ]
341
  })
342
  ]
343
- else: # Вечер после 19:00
344
  urls = [
345
  (f"{base_url}/email/lists/{list_id1}/recipients_thu_evening", {
346
  "email": email,
347
  "unconfirmed": False,
348
  "values": [
349
- {
350
- "parameter_id": 393120,
351
- "kind": "string",
352
- "list_id": list_id1,
353
- "title": "phone",
354
- "value": phone
355
- },
356
- {
357
- "parameter_id": 393119,
358
- "kind": "string",
359
- "list_id": list_id1,
360
- "title": "name",
361
- "value": name
362
- }
363
  ]
364
  })
365
  ]
@@ -378,9 +264,14 @@ def save_pl():
378
  'response_text': response.text
379
  })
380
 
381
- return jsonify({'responses': responses})
382
-
383
-
 
 
 
 
 
384
 
385
 
386
 
 
135
 
136
 
137
 
 
 
138
  @app.route('/save_pl', methods=['POST'])
139
  def save_pl():
140
  list_id1 = 560768
141
  list_id2 = 560832
142
+ list_id3 = 560833
143
+
144
  data = request.json
145
  name = data.get('name')
146
  email = data.get('email')
147
  phone = data.get('phone')
148
 
 
149
  current_day = datetime.datetime.today().weekday()
150
 
151
  urls = []
152
 
 
153
  if current_day in [0, 4, 5, 6]:
154
  urls = [
155
  (f"{base_url}/email/lists/{list_id1}/recipients_mon_fri_sat_sun", {
156
  "email": email,
157
  "unconfirmed": True,
158
  "values": [
159
+ {"parameter_id": 393120, "kind": "string", "list_id": list_id1, "title": "phone", "value": phone},
160
+ {"parameter_id": 393119, "kind": "string", "list_id": list_id1, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
161
  ]
162
  }),
163
  (f"{base_url}/email/lists/{list_id2}/recipients_mon_fri_sat_sun", {
164
  "email": email,
165
  "unconfirmed": True,
166
  "values": [
167
+ {"parameter_id": 393196, "kind": "string", "list_id": list_id2, "title": "phone", "value": phone},
168
+ {"parameter_id": 393195, "kind": "string", "list_id": list_id2, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
169
  ]
170
  }),
171
  (f"{base_url}/email/lists/{list_id3}/recipients_mon_fri_sat_sun", {
172
  "email": email,
173
  "unconfirmed": True,
174
  "values": [
175
+ {"parameter_id": 393198, "kind": "string", "list_id": list_id3, "title": "phone", "value": phone},
176
+ {"parameter_id": 393197, "kind": "string", "list_id": list_id3, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
177
  ]
178
  })
179
  ]
 
180
  elif current_day == 1:
181
  current_time = datetime.datetime.now().time()
182
+ if current_time < datetime.time(19, 0):
183
  urls = [
184
  (f"{base_url}/email/lists/{list_id1}/recipients_tue_morning", {
185
  "email": email,
186
  "unconfirmed": True,
187
  "values": [
188
+ {"parameter_id": 393120, "kind": "string", "list_id": list_id1, "title": "phone", "value": phone},
189
+ {"parameter_id": 393119, "kind": "string", "list_id": list_id1, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
190
  ]
191
  })
192
  ]
193
+ else:
194
  urls = [
195
  (f"{base_url}/email/lists/{list_id1}/recipients_tue_evening", {
196
  "email": email,
197
  "unconfirmed": False,
198
  "values": [
199
+ {"parameter_id": 393120, "kind": "string", "list_id": list_id1, "title": "phone", "value": phone},
200
+ {"parameter_id": 393119, "kind": "string", "list_id": list_id1, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
201
  ]
202
  })
203
  ]
 
204
  elif current_day == 2:
205
  current_time = datetime.datetime.now().time()
206
+ if current_time < datetime.time(19, 0):
207
  urls = [
208
  (f"{base_url}/email/lists/{list_id1}/recipients_wed_morning", {
209
  "email": email,
210
  "unconfirmed": True,
211
  "values": [
212
+ {"parameter_id": 393120, "kind": "string", "list_id": list_id1, "title": "phone", "value": phone},
213
+ {"parameter_id": 393119, "kind": "string", "list_id": list_id1, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
214
  ]
215
  })
216
  ]
217
+ else:
218
  urls = [
219
  (f"{base_url}/email/lists/{list_id1}/recipients_wed_evening", {
220
  "email": email,
221
  "unconfirmed": False,
222
  "values": [
223
+ {"parameter_id": 393120, "kind": "string", "list_id": list_id1, "title": "phone", "value": phone},
224
+ {"parameter_id": 393119, "kind": "string", "list_id": list_id1, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
225
  ]
226
  })
227
  ]
 
228
  elif current_day == 3:
229
  current_time = datetime.datetime.now().time()
230
+ if current_time < datetime.time(19, 0):
231
  urls = [
232
  (f"{base_url}/email/lists/{list_id1}/recipients_thu_morning", {
233
  "email": email,
234
  "unconfirmed": True,
235
  "values": [
236
+ {"parameter_id": 393120, "kind": "string", "list_id": list_id1, "title": "phone", "value": phone},
237
+ {"parameter_id": 393119, "kind": "string", "list_id": list_id1, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
238
  ]
239
  })
240
  ]
241
+ else:
242
  urls = [
243
  (f"{base_url}/email/lists/{list_id1}/recipients_thu_evening", {
244
  "email": email,
245
  "unconfirmed": False,
246
  "values": [
247
+ {"parameter_id": 393120, "kind": "string", "list_id": list_id1, "title": "phone", "value": phone},
248
+ {"parameter_id": 393119, "kind": "string", "list_id": list_id1, "title": "name", "value": name}
 
 
 
 
 
 
 
 
 
 
 
 
249
  ]
250
  })
251
  ]
 
264
  'response_text': response.text
265
  })
266
 
267
+ if show_params:
268
+ system_vars = {
269
+ 'base_url': base_url,
270
+ 'token': token
271
+ }
272
+ return jsonify({'system_variables': system_vars, 'request_parameters': request.args})
273
+ else:
274
+ return jsonify({'responses': responses})
275
 
276
 
277