DmitrMakeev commited on
Commit
11adb51
·
verified ·
1 Parent(s): adb7cc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +274 -1
app.py CHANGED
@@ -19,7 +19,205 @@ wa_url = os.getenv('wa_url')
19
  wa_api_key = os.getenv('wa_api_key')
20
 
21
 
22
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
 
25
 
@@ -65,6 +263,81 @@ for db in DATABASES:
65
  init_db(db)
66
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  def randomize_message(template):
70
  def replace_placeholder(match):
 
19
  wa_api_key = os.getenv('wa_api_key')
20
 
21
 
22
+ json_data = '''
23
+ {
24
+ "success": true,
25
+ "error_message": "",
26
+ "error": false,
27
+ "info": {
28
+ "fields": [
29
+ "id",
30
+ "Email",
31
+ "Тип регистрации",
32
+ "Создан",
33
+ "Последняя активность",
34
+ "Имя",
35
+ "Фамилия",
36
+ "Телефон",
37
+ "Дата рождения",
38
+ "Возраст",
39
+ "Страна",
40
+ "Город",
41
+ "От партнера",
42
+ "Руч продлен Клуба",
43
+ "Промокод",
44
+ "bonus_05_23",
45
+ "Клуб 255 - колл. оплат",
46
+ "Согласен с договором оферты и политикой конфиденциальности",
47
+ "Согласен на рассылку",
48
+ "vk_id",
49
+ "chat_id",
50
+ "ws_st",
51
+ "ws_stop",
52
+ "web_st",
53
+ "fin_prog",
54
+ "shop_st",
55
+ "cur",
56
+ "pr1",
57
+ "pr2",
58
+ "pr3",
59
+ "pr4",
60
+ "pr5",
61
+ "ad_url",
62
+ "Откуда пришел",
63
+ "utm_source",
64
+ "utm_medium",
65
+ "utm_campaign",
66
+ "utm_term",
67
+ "utm_content",
68
+ "utm_group",
69
+ "ID партнера",
70
+ "Email партнера",
71
+ "ФИО партнера",
72
+ "ФИО менеджера",
73
+ "VK-ID"
74
+ ],
75
+ "items": [
76
+ [
77
+ "222077476",
78
79
+ "Зарегистрировался самостоятельно",
80
+ "2022-01-02 00:02:28",
81
+ "2023-02-09 14:47:19",
82
+ "Виктория",
83
+ "Рассабина",
84
+ "79035576755",
85
+ "1983-12-14",
86
+ "41",
87
+ "Россия",
88
+ "Зеленоград",
89
+ "",
90
+ "",
91
+ "",
92
+ "",
93
+ "",
94
+ "",
95
+ "",
96
+ "",
97
+ "",
98
+ "",
99
+ "",
100
+ "",
101
+ "",
102
+ "",
103
+ "",
104
+ "",
105
+ "",
106
+ "",
107
+ "",
108
+ "",
109
+ "",
110
+ "https://l.instagram.com/",
111
+ "instagram",
112
+ "social",
113
+ "",
114
+ "",
115
+ "l.instagram.com",
116
+ "",
117
+ "",
118
+ "",
119
+ "",
120
+ "",
121
+ ""
122
+ ],
123
+ [
124
+ "222211343",
125
126
+ "Зарегистрировался самостоятельно",
127
+ "2022-01-02 19:51:49",
128
+ "2023-01-12 21:14:40",
129
+ "Ирина",
130
+ "",
131
+ "79772623489",
132
+ "",
133
+ "",
134
+ "Россия",
135
+ "",
136
+ "",
137
+ "",
138
+ "",
139
+ "",
140
+ "",
141
+ "",
142
+ "",
143
+ "",
144
+ "",
145
+ "",
146
+ "",
147
+ "",
148
+ "",
149
+ "",
150
+ "",
151
+ "",
152
+ "",
153
+ "",
154
+ "",
155
+ "",
156
+ "",
157
+ "https://www.instagram.com/",
158
+ "instagram",
159
+ "social",
160
+ "",
161
+ "",
162
+ "instagram.com",
163
+ "",
164
+ "",
165
+ "",
166
+ "",
167
+ "",
168
+ ""
169
+ ],
170
+ [
171
+ "226526358",
172
173
+ "Создан через api",
174
+ "2022-01-19 18:28:05",
175
+ "2022-01-20 02:16:21",
176
+ "",
177
+ "",
178
+ "",
179
+ "",
180
+ "",
181
+ "",
182
+ "",
183
+ "",
184
+ "",
185
+ "",
186
+ "",
187
+ "",
188
+ "",
189
+ "",
190
+ "",
191
+ "",
192
+ "",
193
+ "",
194
+ "",
195
+ "",
196
+ "",
197
+ "",
198
+ "",
199
+ "",
200
+ "",
201
+ "",
202
+ "",
203
+ "",
204
+ "",
205
+ "",
206
+ "",
207
+ "",
208
+ "",
209
+ "",
210
+ "",
211
+ "",
212
+ "",
213
+ "",
214
+ "",
215
+ ""
216
+ ]
217
+ ]
218
+ }
219
+ }
220
+ '''
221
 
222
 
223
 
 
263
  init_db(db)
264
 
265
 
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+ def load_data_from_json():
291
+ data = json.loads(json_data)
292
+ items = data['info']['items']
293
+ fields = data['info']['fields']
294
+
295
+ for db in DATABASES:
296
+ conn = sqlite3.connect(db)
297
+ cursor = conn.cursor()
298
+
299
+ for item in items:
300
+ user_data = dict(zip(fields, item))
301
+ query = '''
302
+ INSERT INTO contacts (
303
+ name, phone, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress, shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator
304
+ ) VALUES (
305
+ :Имя, :Телефон, :Email, :vk_id, :chat_id, :ws_st, :ws_stop, :web_st, :fin_prog, :shop_st, :pr1, :pr2, :pr3, :pr4, :pr5, :ad_url, :curator
306
+ )
307
+ '''
308
+ cursor.execute(query, user_data)
309
+
310
+ conn.commit()
311
+ conn.close()
312
+
313
+ @app.before_first_request
314
+ def before_first_request():
315
+ load_data_from_json()
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
 
342
  def randomize_message(template):
343
  def replace_placeholder(match):