<commit_before># script for sending email repsonse

# import module for emailing
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

def emailresponse(emailaddress, outdir, outfile, runerror=False):
  # email a link to the webpage
  fromaddr = '<EMAIL>'
  toaddr = emailaddress

  link = 'http://www.theonlinemcmc.com/%s/%s' % (outdir, outfile)

  subject = 'Your results from TheOnlineMCMC'

  username = 'theonlinemcmc'
  password = '<PASSWORD>' # will need to sort out reading this from a file that is not in the repo

  msg = MIMEMultipart()
  msg['From'] = 'TheOnlineMCMC'
  msg['Subject'] = subject
  
  msgtext = """
Dear user,

{msgtext}

Regards,

TheOnlineMCMC
"""

  # message if there's been an error
  if runerror:
    msgtext = "Unfortunately there was an error in running your MCMC. Please see {0} for more information on the error that occured.".format(link)
  else:
    msgtext = "You data has been analysed. The results can be found at {0}."format(link)
  
  msg.attach(MIMEText(msgtext.format(msgtext=msgtext)))
  
  # set server and send email
  server = smtplib.SMTP_SSL('smtp.gmail.com:465')
  server.login(username,password)
  server.sendmail(fromaddr, toaddrs, msg.as_string())
  server.quit()<commit_msg>emailresponse.py: change to read in email info from file<commit_after># script for sending email repsonse
import os
import json

# import module for emailing
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

def emailresponse(emailaddress, outdir, outfile, runerror=False):
  # read info for emailing
  einf = open(os.environ['EMAILFILE'], 'r')
  edata = json.load(einf)
  einf.close()

  # email a link to the webpage
  fromaddr = edata['fromaddress']
  toaddr = emailaddress

  link = 'http://www.theonlinemcmc.com/%s/%s' % (outdir, outfile)

  subject = 'Your results from TheOnlineMCMC'

  username = edata['username']
  password = edata['password'] # will need to sort out reading this from a file that is not in the repo

  msg = MIMEMultipart()
  msg['From'] = 'TheOnlineMCMC'
  msg['Subject'] = subject
  
  msgtext = """
Dear user,

{msgtext}

Regards,

TheOnlineMCMC
"""

  # message if there's been an error
  if runerror:
    msgtext = "Unfortunately there was an error in running your MCMC. Please see {0} for more information on the error that occured.".format(link)
  else:
    msgtext = "You data has been analysed. The results can be found at {0}."format(link)
  
  msg.attach(MIMEText(msgtext.format(msgtext=msgtext)))
  
  # set server and send email
  server = smtplib.SMTP_SSL(edata['server'])
  server.login(username,password)
  server.sendmail(fromaddr, toaddrs, msg.as_string())
  server.quit()
{'fraction_non_alphanumeric': 0.10564663023679417, 'fraction_numerical': 0.0025500910746812386, 'mean_word_length': 4.250478011472276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6369261', 'n_tokens_mistral': 922, 'n_tokens_neox': 896, 'n_words': 285}