|
19 | 19 |
|
20 | 20 | def export_documents_json(course_name: str, from_date='', to_date=''):
|
21 | 21 | """
|
22 |
| - This function exports the documents to a csv file. |
| 22 | + This function exports the documents to a json file. |
| 23 | + 1. If the number of documents is greater than 1000, it calls a background task to upload the documents to S3. |
| 24 | + 2. If the number of documents is less than 1000, it fetches the documents and zips them. |
23 | 25 | Args:
|
24 | 26 | course_name (str): The name of the course.
|
25 | 27 | from_date (str, optional): The start date for the data export. Defaults to ''.
|
@@ -198,14 +200,27 @@ def export_data_in_bg(response, download_type, course_name, s3_path):
|
198 | 200 | course_metadata = response.json()
|
199 | 201 | course_metadata = json.loads(course_metadata['result'])
|
200 | 202 | admin_emails = course_metadata['course_admins']
|
| 203 | + bcc_emails = [] |
| 204 | + |
| 205 | + # check for Kastan's email and move to bcc |
| 206 | + if '[email protected]' in admin_emails: |
| 207 | + admin_emails. remove( '[email protected]') |
| 208 | + bcc_emails. append( '[email protected]') |
| 209 | + |
| 210 | + # add course owner email to admin_emails |
201 | 211 | admin_emails.append(course_metadata['course_owner'])
|
202 | 212 | admin_emails = list(set(admin_emails))
|
203 | 213 | print("admin_emails: ", admin_emails)
|
| 214 | + print("bcc_emails: ", bcc_emails) |
| 215 | + |
| 216 | + # add a check for emails, don't send email if no admin emails |
| 217 | + if len(admin_emails) == 0: |
| 218 | + return "No admin emails found. Email not sent." |
204 | 219 |
|
205 | 220 | # send email to admins
|
206 | 221 | subject = "UIUC.chat Data Export Complete for " + course_name
|
207 | 222 | body_text = "The data export for " + course_name + " is complete.\n\nYou can download the file from the following link: \n\n" + s3_url + "\n\nThis link will expire in 48 hours."
|
208 |
| - email_status = send_email(subject, body_text, os.getenv('EMAIL_SENDER'), admin_emails) |
| 223 | + email_status = send_email(subject, body_text, os.getenv('EMAIL_SENDER'), admin_emails, bcc_emails) |
209 | 224 | print("email_status: ", email_status)
|
210 | 225 |
|
211 | 226 | return "File uploaded to S3. Email sent to admins."
|
|
0 commit comments