简体   繁体   English

在Python应用中安排日常任务

[英]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. 一般而言,我在Python上还算是新手,但是我正在尝试创建一个小型的后台应用程序,该应用程序将读取excel文件并在某些情况下每天向我发送电子邮件。 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/ 看看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 如何从Excel文件读取

  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 让我知道您是否也想详细说明这些要点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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