Spaces:
Sleeping
Sleeping
DmitrMakeev
commited on
Commit
•
edee679
1
Parent(s):
4289d2d
Update app.py
Browse files
app.py
CHANGED
@@ -1,120 +1,92 @@
|
|
1 |
from flask import Flask, request, render_template, jsonify
|
|
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
app = Flask(__name__, template_folder="./")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
return render_template('grups.html')
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
headers = {
|
22 |
-
'Content-Type': 'application/json',
|
23 |
-
'Authorization': f'Bearer {api_token}'
|
24 |
-
}
|
25 |
-
response = requests.get(url, headers=headers)
|
26 |
-
data = response.json()
|
27 |
-
return jsonify(data)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
pr1_id = request.args.get('pr1_id')
|
40 |
-
pr2 = request.args.get('pr2')
|
41 |
-
pr2_id = request.args.get('pr2_id')
|
42 |
-
pr3 = request.args.get('pr3')
|
43 |
-
pr3_id = request.args.get('pr3_id')
|
44 |
-
pr4 = request.args.get('pr4')
|
45 |
-
pr4_id = request.args.get('pr4_id')
|
46 |
-
pr5 = request.args.get('pr5')
|
47 |
-
pr5_id = request.args.get('pr5_id')
|
48 |
-
data = {
|
49 |
-
"email": email,
|
50 |
-
"unconfirmed": False,
|
51 |
-
"values": [
|
52 |
-
{
|
53 |
-
"parameter_id": pr5_id,
|
54 |
-
"kind": "string",
|
55 |
-
"list_id": list_id,
|
56 |
-
"title": "pr5",
|
57 |
-
"value": pr5
|
58 |
-
},
|
59 |
-
{
|
60 |
-
"parameter_id": pr4_id,
|
61 |
-
"kind": "string",
|
62 |
-
"list_id": list_id,
|
63 |
-
"title": "pr4",
|
64 |
-
"value": pr4
|
65 |
-
},
|
66 |
-
{
|
67 |
-
"parameter_id": pr3_id,
|
68 |
-
"kind": "string",
|
69 |
-
"list_id": list_id,
|
70 |
-
"title": "pr3",
|
71 |
-
"value": pr3
|
72 |
-
},
|
73 |
-
{
|
74 |
-
"parameter_id": pr2_id,
|
75 |
-
"kind": "string",
|
76 |
-
"list_id": list_id,
|
77 |
-
"title": "pr2",
|
78 |
-
"value": pr2
|
79 |
-
},
|
80 |
-
{
|
81 |
-
"parameter_id": pr1_id,
|
82 |
-
"kind": "string",
|
83 |
-
"list_id": list_id,
|
84 |
-
"title": "pr1",
|
85 |
-
"value": pr1
|
86 |
-
},
|
87 |
-
{
|
88 |
-
"parameter_id": phone_id,
|
89 |
-
"kind": "string",
|
90 |
-
"list_id": list_id,
|
91 |
-
"title": "phone",
|
92 |
-
"value": phone
|
93 |
-
},
|
94 |
-
{
|
95 |
-
"parameter_id": name_id,
|
96 |
-
"kind": "string",
|
97 |
-
"list_id": list_id,
|
98 |
-
"title": "name",
|
99 |
-
"value": name
|
100 |
-
}
|
101 |
-
]
|
102 |
-
}
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
|
111 |
-
system_vars = {
|
112 |
-
'base_url': base_url,
|
113 |
-
'token': token
|
114 |
-
}
|
115 |
-
return jsonify({'system_variables': system_vars, 'request_parameters': request.args})
|
116 |
-
else:
|
117 |
-
return response.text
|
118 |
|
119 |
if __name__ == '__main__':
|
120 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
1 |
from flask import Flask, request, render_template, jsonify
|
2 |
+
import sqlite3
|
3 |
import requests
|
4 |
import os
|
5 |
|
6 |
app = Flask(__name__, template_folder="./")
|
7 |
|
8 |
+
# Создание базы данных и таблицы
|
9 |
+
def init_db():
|
10 |
+
conn = sqlite3.connect('data.db')
|
11 |
+
cursor = conn.cursor()
|
12 |
+
cursor.execute('''
|
13 |
+
CREATE TABLE IF NOT EXISTS contacts (
|
14 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
15 |
+
name TEXT NOT NULL,
|
16 |
+
phone TEXT NOT NULL
|
17 |
+
)
|
18 |
+
''')
|
19 |
+
conn.commit()
|
20 |
+
conn.close()
|
21 |
|
22 |
+
# Маршрут для обработки GET-запроса
|
23 |
+
@app.route('/add_contact', methods=['GET'])
|
24 |
+
def add_contact():
|
25 |
+
name = request.args.get('name')
|
26 |
+
phone = request.args.get('phone')
|
27 |
|
28 |
+
if not name or not phone:
|
29 |
+
return "Both 'name' and 'phone' parameters are required.", 400
|
|
|
30 |
|
31 |
+
conn = sqlite3.connect('data.db')
|
32 |
+
cursor = conn.cursor()
|
33 |
+
cursor.execute('INSERT INTO contacts (name, phone) VALUES (?, ?)', (name, phone))
|
34 |
+
conn.commit()
|
35 |
+
conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
return f"Contact added: {name} - {phone}", 200
|
38 |
+
|
39 |
+
# Маршрут для отображения таблицы контактов
|
40 |
+
@app.route('/contacts')
|
41 |
+
def show_contacts():
|
42 |
+
conn = sqlite3.connect('data.db')
|
43 |
+
cursor = conn.cursor()
|
44 |
+
cursor.execute('SELECT name, phone FROM contacts')
|
45 |
+
contacts = cursor.fetchall()
|
46 |
+
conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
# HTML-шаблон для отображения таблицы
|
49 |
+
html = '''
|
50 |
+
<!doctype html>
|
51 |
+
<html lang="en">
|
52 |
+
<head>
|
53 |
+
<meta charset="utf-8">
|
54 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
55 |
+
<title>Contacts</title>
|
56 |
+
<style>
|
57 |
+
table {
|
58 |
+
width: 50%;
|
59 |
+
border-collapse: collapse;
|
60 |
+
}
|
61 |
+
th, td {
|
62 |
+
border: 1px solid black;
|
63 |
+
padding: 8px;
|
64 |
+
text-align: left;
|
65 |
+
}
|
66 |
+
th {
|
67 |
+
background-color: #f2f2f2;
|
68 |
+
}
|
69 |
+
</style>
|
70 |
+
</head>
|
71 |
+
<body>
|
72 |
+
<h1>Contacts</h1>
|
73 |
+
<table>
|
74 |
+
<tr>
|
75 |
+
<th>Name</th>
|
76 |
+
<th>Phone</th>
|
77 |
+
</tr>
|
78 |
+
{% for contact in contacts %}
|
79 |
+
<tr>
|
80 |
+
<td>{{ contact[0] }}</td>
|
81 |
+
<td>{{ contact[1] }}</td>
|
82 |
+
</tr>
|
83 |
+
{% endfor %}
|
84 |
+
</table>
|
85 |
+
</body>
|
86 |
+
</html>
|
87 |
+
'''
|
88 |
|
89 |
+
return render_template_string(html, contacts=contacts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
if __name__ == '__main__':
|
92 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|