DmitrMakeev commited on
Commit
fc5f4be
·
verified ·
1 Parent(s): 4e89dc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -733,19 +733,37 @@ def save_db():
733
 
734
 
735
 
736
- @app.route('/contacts')
737
- def show_contacts():
738
  try:
739
  conn = sqlite3.connect('data.db')
740
  cursor = conn.cursor()
741
  cursor.execute('SELECT name, email, phone, pr1, pr2, pr3, pr4, pr5, date, time FROM contacts')
742
  contacts = cursor.fetchall()
743
  conn.close()
744
- return render_template('contacts.html', contacts=contacts)
745
- except Exception as e:
746
- print(f"Error showing contacts: {e}")
747
- return "Database error. Please try again later.", 500
748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
 
750
 
751
 
 
733
 
734
 
735
 
736
+ @app.route('/conta')
737
+ def get_contacts_json():
738
  try:
739
  conn = sqlite3.connect('data.db')
740
  cursor = conn.cursor()
741
  cursor.execute('SELECT name, email, phone, pr1, pr2, pr3, pr4, pr5, date, time FROM contacts')
742
  contacts = cursor.fetchall()
743
  conn.close()
 
 
 
 
744
 
745
+ # Prepare JSON response
746
+ contacts_json = []
747
+ for contact in contacts:
748
+ contact_dict = {
749
+ 'name': contact[0],
750
+ 'email': contact[1],
751
+ 'phone': contact[2],
752
+ 'pr1': contact[3],
753
+ 'pr2': contact[4],
754
+ 'pr3': contact[5],
755
+ 'pr4': contact[6],
756
+ 'pr5': contact[7],
757
+ 'date': contact[8],
758
+ 'time': contact[9]
759
+ }
760
+ contacts_json.append(contact_dict)
761
+
762
+ return jsonify(contacts_json), 200 # Return JSON response with contacts data
763
+
764
+ except Exception as e:
765
+ print(f"Error getting contacts JSON: {e}")
766
+ return jsonify({'error': 'Database error. Please try again later.'}), 500
767
 
768
 
769