AMead10 commited on
Commit
2409abe
·
1 Parent(s): b9befae

split up query

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -81,19 +81,16 @@ def save_data(orig_user_email, constituent_email, labels, user_response):
81
  db_cursor = db_connection.cursor()
82
 
83
  try:
84
- print("saving first email")
85
  db_cursor.execute(
86
  "INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', 0)",
87
  (orig_user_email,),
88
  )
89
 
90
- print("saving constituent email")
91
  db_cursor.execute(
92
  "INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', 1)",
93
  (constituent_email,),
94
  )
95
 
96
- print("saving user response")
97
  db_cursor.execute(
98
  "INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', 2)",
99
  (user_response,),
@@ -102,20 +99,21 @@ def save_data(orig_user_email, constituent_email, labels, user_response):
102
  # insert a row into the message_categorys_associations table for each valid label in labels with the message_id of the constituent_email
103
  labels = labels.split(", ")
104
  for label in labels:
105
- print("saving label: " + label)
106
  label_exists = db_cursor.execute(
107
  "SELECT * FROM radmap_frog12.message_categorys WHERE message_category_name = %s",
108
  (label,),
109
  )
110
  label_exists = db_cursor.fetchall()
111
- print(label_exists)
112
  if label_exists:
113
- print("label exists")
 
 
 
 
114
  db_cursor.execute(
115
- "INSERT INTO radmap_frog12.message_category_associations (message_id, message_category_id) VALUES ((SELECT id FROM messages WHERE body = %s), %i)",
116
- (constituent_email, label_exists[0][0]),
117
  )
118
- print("label saved")
119
 
120
  db_connection.commit()
121
 
 
81
  db_cursor = db_connection.cursor()
82
 
83
  try:
 
84
  db_cursor.execute(
85
  "INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', 0)",
86
  (orig_user_email,),
87
  )
88
 
 
89
  db_cursor.execute(
90
  "INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', 1)",
91
  (constituent_email,),
92
  )
93
 
 
94
  db_cursor.execute(
95
  "INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', 2)",
96
  (user_response,),
 
99
  # insert a row into the message_categorys_associations table for each valid label in labels with the message_id of the constituent_email
100
  labels = labels.split(", ")
101
  for label in labels:
 
102
  label_exists = db_cursor.execute(
103
  "SELECT * FROM radmap_frog12.message_categorys WHERE message_category_name = %s",
104
  (label,),
105
  )
106
  label_exists = db_cursor.fetchall()
 
107
  if label_exists:
108
+ message_id = db_cursor.execute(
109
+ "SELECT id FROM messages WHERE body = %s", (constituent_email,)
110
+ )
111
+ message_id = db_cursor.fetchall()
112
+
113
  db_cursor.execute(
114
+ "INSERT INTO radmap_frog12.message_category_associations (message_id, message_category_id) VALUES (%i, %i)",
115
+ (message_id, label_exists[0][0]),
116
  )
 
117
 
118
  db_connection.commit()
119