DmitrMakeev commited on
Commit
2dca593
1 Parent(s): 7c3aff0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -1154,6 +1154,25 @@ def se_upl_csv():
1154
  return "EUR 22", 200
1155
  return render_template('upl_csv.html')
1156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1157
  @app.route('/upload_csv', methods=['POST'])
1158
  def upload_csv():
1159
  if 'file' not in request.files:
@@ -1165,7 +1184,8 @@ def upload_csv():
1165
  stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
1166
  csv_input = csv.DictReader(stream)
1167
  data = [row for row in csv_input]
1168
- return jsonify(data)
 
1169
  return jsonify({"error": "Invalid file format"}), 400
1170
 
1171
 
@@ -1174,6 +1194,7 @@ def upload_csv():
1174
 
1175
 
1176
 
 
1177
  @app.route('/total_users', methods=['GET'])
1178
  def total_users():
1179
  try:
 
1154
  return "EUR 22", 200
1155
  return render_template('upl_csv.html')
1156
 
1157
+ DATABASE2 = 'data_gc.db'
1158
+
1159
+ def insert_data(data):
1160
+ conn = sqlite3.connect(DATABASE2)
1161
+ cursor = conn.cursor()
1162
+ for row in data:
1163
+ # Получение текущего времени в московском часовом поясе
1164
+ utc_now = datetime.utcnow()
1165
+ msk_tz = pytz.timezone('Europe/Moscow')
1166
+ msk_now = utc_now.replace(tzinfo=pytz.utc).astimezone(msk_tz)
1167
+ data_t = msk_now.strftime('%Y-%m-%d %H:%M:%S')
1168
+
1169
+ cursor.execute('''
1170
+ INSERT INTO contacts (name, phone, email, data_t)
1171
+ VALUES (?, ?, ?, ?)
1172
+ ''', (row['Name'], row['Phone'], row['Email'], data_t))
1173
+ conn.commit()
1174
+ conn.close()
1175
+
1176
  @app.route('/upload_csv', methods=['POST'])
1177
  def upload_csv():
1178
  if 'file' not in request.files:
 
1184
  stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
1185
  csv_input = csv.DictReader(stream)
1186
  data = [row for row in csv_input]
1187
+ insert_data(data)
1188
+ return jsonify({"message": "Data uploaded and inserted successfully"})
1189
  return jsonify({"error": "Invalid file format"}), 400
1190
 
1191
 
 
1194
 
1195
 
1196
 
1197
+
1198
  @app.route('/total_users', methods=['GET'])
1199
  def total_users():
1200
  try: