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.
1 Answer
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? -
How to read from excel file
How to automate an email
How to time/ schedule the function call
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
1 Comment
Phil D
Thanks for the answer! I actually looked into this library before, I just wasn't sure how to implement it. Well, I figured out the first two points (email and excel) but my question was more oriented towards the last two (schedule and package). Could you please elaborate on the last point?
python.exe C:\path\to\the\script.py.