DmitrMakeev commited on
Commit
4dbc526
·
verified ·
1 Parent(s): 2247f05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -161
app.py CHANGED
@@ -95,167 +95,6 @@ def up_fa():
95
 
96
 
97
 
98
- # Маршрут для обработки GET-запроса из gc
99
- @app.route('/add_contact', methods=['GET'])
100
- def add_contact():
101
- try:
102
- name = request.args.get('name')
103
- phone = request.args.get('phone')
104
- email = request.args.get('email')
105
-
106
- if not name or not phone or not email:
107
- return "Parameters 'name', 'phone', and 'email' are required.", 400
108
-
109
- conn = sqlite3.connect('data1.db')
110
- cursor = conn.cursor()
111
- cursor.execute('INSERT INTO contacts (name, phone, email) VALUES (?, ?, ?)', (name, phone, email))
112
- conn.commit()
113
- conn.close()
114
-
115
- return f"Contact added: {name} - {phone} - {email}", 200
116
- except Exception as e:
117
- print(f"Error adding contact: {e}")
118
- return "Internal Server Error", 500
119
-
120
- @app.route('/contacts')
121
- def show_contacts():
122
- try:
123
- conn = sqlite3.connect('data1.db')
124
- cursor = conn.cursor()
125
- cursor.execute('SELECT name, phone, email FROM contacts')
126
- contacts = cursor.fetchall()
127
- conn.close()
128
-
129
- html = '''
130
- <!doctype html>
131
- <html lang="en">
132
- <head>
133
- <meta charset="utf-8">
134
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
135
- <title>Contacts</title>
136
- <style>
137
- table {
138
- width: 70%;
139
- border-collapse: collapse;
140
- }
141
- th, td {
142
- border: 1px solid black;
143
- padding: 8px;
144
- text-align: left;
145
- }
146
- th {
147
- background-color: #f2f2f2;
148
- }
149
- </style>
150
- </head>
151
- <body>
152
- <h1>Contacts</h1>
153
- <table>
154
- <tr>
155
- <th>Name</th>
156
- <th>Phone</th>
157
- <th>Email</th>
158
- </tr>
159
- {% for contact in contacts %}
160
- <tr>
161
- <td>{{ contact[0] }}</td>
162
- <td>{{ contact[1] }}</td>
163
- <td>{{ contact[2] }}</td>
164
- </tr>
165
- {% endfor %}
166
- </table>
167
- </body>
168
- </html>
169
- '''
170
-
171
- return render_template_string(html, contacts=contacts)
172
- except Exception as e:
173
- print(f"Error showing contacts: {e}")
174
- return "Internal Server Error", 500
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
- # Переменные с данными
186
-
187
- action_d = "add"
188
- params_d = ""
189
- name_d = ""
190
- email_d = ""
191
- phone_d = ""
192
- pr1_d = ""
193
- pr2_d = ""
194
- pr3_d = ""
195
-
196
- @app.route('/gc_db', methods=['GET'])
197
- def gc_db():
198
- # Чтение параметров из GET-запроса
199
- name_d = request.args.get('name', '')
200
- email_d = request.args.get('email', '')
201
- phone_d = request.args.get('phone', '')
202
- pr1_d = request.args.get('pr1', '')
203
- pr2_d = request.args.get('pr2', '')
204
- pr3_d = request.args.get('pr3', '')
205
-
206
- # Формирование JSON
207
- json_data = {
208
- "user": {
209
- "email": email_d,
210
- "phone": phone_d,
211
- "first_name": name_d,
212
- "addfields": {
213
- "pr1": pr1_d,
214
- "pr2": pr2_d,
215
- "pr3": pr3_d
216
- }
217
- },
218
- "system": {
219
- "refresh_if_exists": 1
220
- },
221
- "session": {
222
- "utm_source": "",
223
- "utm_medium": "",
224
- "utm_content": "",
225
- "utm_campaign": "",
226
- "utm_group": "",
227
- "gcpc": "",
228
- "gcao": "",
229
- "referer": ""
230
- }
231
- }
232
-
233
- # Конвертация JSON в Base64
234
- json_str = json.dumps(json_data)
235
- params_d = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
236
-
237
- # Данные для отправки в теле запроса
238
- data = {
239
- 'key': key_d,
240
- 'action': action_d,
241
- 'params': params_d
242
- }
243
-
244
- # Отправка POST-запроса с данными в формате "form-data"
245
- response = requests.post(gc_url, data=data)
246
-
247
- # Возвращаем ответ от тестового адреса
248
- return {
249
- 'status_code': response.status_code,
250
- 'response_body': response.text
251
- }
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
 
260
 
261
 
 
95
 
96
 
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
 
100