title: Add email send at specified interval to python script
body: <p>I have two python scripts that both work independently.  One logs some data to a log file and the other sends an email to a specified email address. I need to combine these two scripts together so that the email will send the log file at a specified interval.</p>
  
  <p>I have managed to get both scripts working on there own but am not sure how to combine them into one working script.</p>
  
  <p>script 1</p>
  
  <pre><code>def get_titles():
      current_title = None
      while True:
          moment2 = datetime.datetime.now().strftime("%d-%b-%Y [ %H:%M:%S ]")
          new_title = GetWindowText(GetForegroundWindow())
          if new_title != current_title:
             if len(new_title) &gt; 0:
                  #logging.info(" Moved to : " + new_title)
                  current_title = new_title
                  time.sleep(0.1)
                  #print(new_title)
                  ff= (moment2 + " : " +  "Moved T0 : "+ new_title + '\n')
                  #print (ff)
                  with open('logfile.txt', 'a+') as f:
                    f.write(ff)
  </code></pre>
  
  <p>script 2</p>
  
  <pre><code>body = "Please see attatched file for info"
  msg.attach(MIMEText(body, 'plain'))
  
  filename = "logfile.txt"
  attachment = open("logfile.txt", "rb")
  
  part = MIMEBase('application', 'octet-stream')
  part.set_payload((attachment).read())
  encoders.encode_base64(part)
  part.add_header('Content-Disposition',"attachment; filename= "+filename)
  
  msg.attach(part)
  
  server = smtplib.SMTP('smtpname', 587)
  server.starttls()
  server.login(fromaddr, password)
  text = msg.as_string()
  server.sendmail(fromaddr, toaddr, text)
  server.quit()
  </code></pre>