DmitrMakeev commited on
Commit
04d4d7b
1 Parent(s): e4c74f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py CHANGED
@@ -152,6 +152,69 @@ def start_mailings():
152
 
153
 
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
 
157
 
 
152
 
153
 
154
 
155
+ @app.route('/add_data_gc', methods=['GET'])
156
+ def add_data_gc():
157
+ try:
158
+ api_sys_control = request.args.get('api_sys')
159
+
160
+ if api_sys_control != api_key_sys:
161
+ return "EUR 22", 200
162
+
163
+ name = request.args.get('name')
164
+ phone = request.args.get('phone')
165
+ email = request.args.get('email')
166
+ vk_id = request.args.get('vk_id', '')
167
+ chat_id = request.args.get('chat_id', '')
168
+ ws_statys = request.args.get('ws_st', '')
169
+ ws_stop = request.args.get('ws_stop', '')
170
+ web_statys = request.args.get('web_st', 0, type=int)
171
+ fin_progress = request.args.get('fin_prog', 0, type=int)
172
+ shop_statys_full = request.args.get('shop_st', '')
173
+ pr1 = request.args.get('pr1', '')
174
+ pr2 = request.args.get('pr2', '')
175
+ pr3 = request.args.get('pr3', '')
176
+ pr4 = request.args.get('pr4', '')
177
+ pr5 = request.args.get('pr5', '')
178
+ ad_url = request.args.get('ad_url', '')
179
+ curator = request.args.get('curator', '')
180
+
181
+ if not name or not phone or not email:
182
+ return "Parameters 'name', 'phone', and 'email' are required.", 400
183
+
184
+ # Clean up phone number by removing any leading plus sign
185
+ if phone.startswith('+'):
186
+ phone = phone[1:]
187
+
188
+ conn = sqlite3.connect('data_gc.db')
189
+ cursor = conn.cursor()
190
+ cursor.execute('SELECT * FROM contacts WHERE phone = ? OR email = ?', (phone, email))
191
+ existing_contact = cursor.fetchone()
192
+
193
+ if existing_contact:
194
+ cursor.execute('''
195
+ UPDATE contacts SET
196
+ name = ?, email = ?, vk_id = ?, chat_id = ?, ws_statys = ?, ws_stop = ?,
197
+ web_statys = ?, fin_progress = ?, shop_statys_full = ?, pr1 = ?, pr2 = ?,
198
+ pr3 = ?, pr4 = ?, pr5 = ?, ad_url = ?, curator = ?
199
+ WHERE phone = ? OR email = ?
200
+ ''', (name, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress,
201
+ shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator, phone, email))
202
+ else:
203
+ cursor.execute('''
204
+ INSERT INTO contacts (
205
+ name, phone, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress,
206
+ shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator
207
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
208
+ ''', (name, phone, email, vk_id, chat_id, ws_statys, ws_stop, web_statys, fin_progress,
209
+ shop_statys_full, pr1, pr2, pr3, pr4, pr5, ad_url, curator))
210
+
211
+ conn.commit()
212
+ conn.close()
213
+
214
+ return f"Contact updated/added: {name} - {phone} - {email}", 200
215
+ except Exception as e:
216
+ print(f"Error adding/updating contact: {e}")
217
+ return "Internal Server Error", 500
218
 
219
 
220