简体   繁体   中英

Schedule daily task in a Python app

I'm fairly new at Python in general, but I'm trying to create a small background application that will read an excel file and send me an e-mail every day on some condition. I was wondering what is the best way to go about this? Should I just use some sort of loop where it does the action every so many seconds, and then execute the script from the command line? Is there a way to make it into a standalone background app? Thanks for your answers.

Take a look at http://apscheduler.readthedocs.org/en/3.0/

Here is an example from there site:

from datetime import datetime
import os

from apscheduler.schedulers.blocking import BlockingScheduler


def tick():
    print('Tick! The time is: %s' % datetime.now())


if __name__ == '__main__':
    scheduler = BlockingScheduler()
    scheduler.add_executor('processpool')
    scheduler.add_job(tick, 'interval', seconds=3)
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

try:
    scheduler.start()
except (KeyboardInterrupt, SystemExit):
    pass

Edit: I assumed this was the main point of your question. Re -reading however, are you wanting to know the whole process? -

  1. How to read from excel file

  2. How to automate an email

  3. How to time/ schedule the function call

  4. How to package as a desktop app

That is a loaded question. Let me know if you want me to elaborate on those points too

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM