Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from dotenv import load_dotenv
|
|
9 |
import globs
|
10 |
from flask import render_template
|
11 |
|
12 |
-
|
13 |
from api_logic import api
|
14 |
|
15 |
|
@@ -90,6 +90,96 @@ globs.l_OFF_m_eep = 0
|
|
90 |
globs.t_Voz_eep = 0
|
91 |
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
app = flask.Flask(__name__, template_folder="./")
|
94 |
app.config['DEBUG'] = True
|
95 |
|
|
|
9 |
import globs
|
10 |
from flask import render_template
|
11 |
|
12 |
+
from datetime import datetime
|
13 |
from api_logic import api
|
14 |
|
15 |
|
|
|
90 |
globs.t_Voz_eep = 0
|
91 |
|
92 |
|
93 |
+
|
94 |
+
|
95 |
+
# Функция сохранения в базу
|
96 |
+
def save_data_to_db(db_name, data):
|
97 |
+
conn = sqlite3.connect(db_name)
|
98 |
+
cursor = conn.cursor()
|
99 |
+
|
100 |
+
# Получаем текущую дату и время
|
101 |
+
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
102 |
+
|
103 |
+
# Вставляем данные в таблицу
|
104 |
+
cursor.execute('''
|
105 |
+
INSERT INTO system_data (
|
106 |
+
date_time, dey, wek, v_hid, v_min, ph, ec, tS, tA, hDm, sVen, rFul, rLi, rWat, rRas, rPH, rEC, rSl, rLe, alW
|
107 |
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
108 |
+
''', (
|
109 |
+
current_time, # Дата и время
|
110 |
+
data['dey'], data['wek'], data['v_hid'], data['v_min'], data['ph'], data['ec'],
|
111 |
+
data['tS'], data['tA'], data['hDm'], data['sVen'], data['rFul'], data['rLi'],
|
112 |
+
data['rWat'], data['rRas'], data['rPH'], data['rEC'], data['rSl'], data['rLe'], data['alW']
|
113 |
+
))
|
114 |
+
|
115 |
+
conn.commit()
|
116 |
+
conn.close()
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
# Мвршрут сохранения в базу
|
122 |
+
@app.route('/online_api', methods=['GET'])
|
123 |
+
def online_api():
|
124 |
+
# Получаем данные из запроса
|
125 |
+
data = {
|
126 |
+
'dey': request.args.get('dey'),
|
127 |
+
'wek': request.args.get('wek'),
|
128 |
+
'v_hid': request.args.get('v_hid'),
|
129 |
+
'v_min': request.args.get('v_min'),
|
130 |
+
'ph': request.args.get('ph'),
|
131 |
+
'ec': request.args.get('ec'),
|
132 |
+
'tS': request.args.get('tS'),
|
133 |
+
'tA': request.args.get('tA'),
|
134 |
+
'hDm': request.args.get('hDm'),
|
135 |
+
'sVen': request.args.get('sVen'),
|
136 |
+
'rFul': request.args.get('rFul'),
|
137 |
+
'rLi': request.args.get('rLi'),
|
138 |
+
'rWat': request.args.get('rWat'),
|
139 |
+
'rRas': request.args.get('rRas'),
|
140 |
+
'rPH': request.args.get('rPH'),
|
141 |
+
'rEC': request.args.get('rEC'),
|
142 |
+
'rSl': request.args.get('rSl'),
|
143 |
+
'rLe': request.args.get('rLe'),
|
144 |
+
'alW': request.args.get('alW')
|
145 |
+
}
|
146 |
+
|
147 |
+
# Сохраняем данные в базу
|
148 |
+
save_data_to_db('system_data.db', data)
|
149 |
+
|
150 |
+
# Возвращаем ответ
|
151 |
+
return jsonify(data)
|
152 |
+
|
153 |
+
|
154 |
+
|
155 |
+
|
156 |
+
|
157 |
+
# Маршрут для вывода всех данных из таблицы
|
158 |
+
@app.route('/get_all_data', methods=['GET'])
|
159 |
+
def get_all_data():
|
160 |
+
conn = sqlite3.connect('system_data.db')
|
161 |
+
cursor = conn.cursor()
|
162 |
+
|
163 |
+
# Выполняем запрос для получения всех данных из таблицы
|
164 |
+
cursor.execute('SELECT * FROM system_data')
|
165 |
+
rows = cursor.fetchall()
|
166 |
+
|
167 |
+
# Получаем названия столбцов
|
168 |
+
column_names = [description[0] for description in cursor.description]
|
169 |
+
|
170 |
+
# Преобразуем данные в формат JSON
|
171 |
+
data = []
|
172 |
+
for row in rows:
|
173 |
+
data.append(dict(zip(column_names, row)))
|
174 |
+
|
175 |
+
conn.close()
|
176 |
+
|
177 |
+
# Возвращаем данные в формате JSON
|
178 |
+
return jsonify(data)
|
179 |
+
|
180 |
+
|
181 |
+
|
182 |
+
|
183 |
app = flask.Flask(__name__, template_folder="./")
|
184 |
app.config['DEBUG'] = True
|
185 |
|