mojoblojo commited on
Commit
c32e9a7
·
verified ·
1 Parent(s): 638f6c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -27
app.py CHANGED
@@ -19,7 +19,8 @@ SHEET_NAME = 'Form Responses 2'
19
  OUTPUT_DIR = 'downloads'
20
  EMAIL_ADDRESS = '[email protected]'
21
  EMAIL_PASSWORD = 'ijpo nrpj xpxv bqgn'
22
- GOOGLE_CREDS_PATH = './optical-mode-424508-f5-ab5944b9ea6a.json' # Update to match the location of your credentials file
 
23
 
24
  # Function to download MP3 file from Google Drive
25
  def download_mp3_from_drive(drive_link, output_file):
@@ -109,44 +110,28 @@ def check_for_new_links(sheet):
109
 
110
  # Function to send email with transcription and summary
111
  def send_email(to_email, transcription, summary):
 
112
  try:
113
- transcription_file_path = os.path.join(OUTPUT_DIR, 'transcription.txt')
114
- summary_file_path = os.path.join(OUTPUT_DIR, 'summary.txt')
115
-
116
- with open(transcription_file_path, 'w') as file:
117
- file.write(transcription)
118
- with open(summary_file_path, 'w') as file:
119
- file.write(summary)
120
-
121
  msg = MIMEMultipart()
122
  msg['From'] = EMAIL_ADDRESS
123
  msg['To'] = to_email
124
- msg['Subject'] = 'Your Audio Transcription and Summary'
125
-
126
- msg.attach(MIMEText('Please find the attached transcription and summary of your audio file.', 'plain'))
127
 
128
- with open(transcription_file_path, 'rb') as file:
129
- attachment = MIMEApplication(file.read(), _subtype='txt')
130
- attachment.add_header('Content-Disposition', 'attachment', filename='transcription.txt')
131
- msg.attach(attachment)
132
 
133
- with open(summary_file_path, 'rb') as file:
134
- attachment = MIMEApplication(file.read(), _subtype='txt')
135
- attachment.add_header('Content-Disposition', 'attachment', filename='summary.txt')
136
- msg.attach(attachment)
 
 
137
 
138
- print("Connecting to SMTP server...")
139
- with smtplib.SMTP('smtp.gmail.com', 587) as server:
140
- server.set_debuglevel(1) # Enable debug output for SMTP
141
  server.starttls()
142
- print("Logging in to SMTP server...")
143
  server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
144
- print("Sending email...")
145
  server.sendmail(EMAIL_ADDRESS, to_email, msg.as_string())
146
 
147
  print(f"Email sent successfully to {to_email}")
148
- os.remove(transcription_file_path)
149
- os.remove(summary_file_path)
150
  return "Email sent successfully"
151
  except smtplib.SMTPAuthenticationError:
152
  print("SMTP Authentication Error: Check your email address and password.")
 
19
  OUTPUT_DIR = 'downloads'
20
  EMAIL_ADDRESS = '[email protected]'
21
  EMAIL_PASSWORD = 'ijpo nrpj xpxv bqgn'
22
+ GOOGLE_CREDS_PATH = './optical-mode-424508-f5-ab5944b9ea6a.json'
23
+ SMTP_PORT = 1025
24
 
25
  # Function to download MP3 file from Google Drive
26
  def download_mp3_from_drive(drive_link, output_file):
 
110
 
111
  # Function to send email with transcription and summary
112
  def send_email(to_email, transcription, summary):
113
+ def send_email(to_email, subject, body, attachments=None):
114
  try:
 
 
 
 
 
 
 
 
115
  msg = MIMEMultipart()
116
  msg['From'] = EMAIL_ADDRESS
117
  msg['To'] = to_email
118
+ msg['Subject'] = subject
 
 
119
 
120
+ msg.attach(MIMEText(body, 'plain'))
 
 
 
121
 
122
+ if attachments:
123
+ for attachment in attachments:
124
+ with open(attachment, 'rb') as file:
125
+ part = MIMEApplication(file.read(), _subtype='txt')
126
+ part.add_header('Content-Disposition', 'attachment', filename=attachment)
127
+ msg.attach(part)
128
 
129
+ with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
 
 
130
  server.starttls()
 
131
  server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
 
132
  server.sendmail(EMAIL_ADDRESS, to_email, msg.as_string())
133
 
134
  print(f"Email sent successfully to {to_email}")
 
 
135
  return "Email sent successfully"
136
  except smtplib.SMTPAuthenticationError:
137
  print("SMTP Authentication Error: Check your email address and password.")