通过声音或电子邮件通知
pynotice的Python项目详细描述
简介
自述文件:English中文
pynotice是一个python3模块,它可以播放声音或发送电子邮件,以通知您功能何时完成或出错。
功能
- 使用默认或自定义wav文件
- 发送带有图片或txt文件附件的电子邮件
- python装饰器
- 不需要指定smtp服务器地址,当然可以这样做
安装
仅限Python3
pip install pynotice
用法
-声音-
在功能完成时播放声音通知您
frompynotice.sound.noticeimportnoticeOnFinish@noticeOnFinish()deffoo(name="foooo"):# your functionreturnnameret=foo()print(ret)
当您的功能出现故障时,通过播放声音通知您
frompynotice.sound.noticeimportnoticeOnException,noticeOnFinish@noticeOnFinish()@noticeOnException()deffoo(name="aaa"):returnname
-电子邮件-
首先,请确认您已在电子邮件中打开SMTP功能。方法取决于您的电子邮件服务器(对于@163.com和@gmail.com,您需要设置应用程序的私人密码)gmail SMTP authorizationqq email SMTP authorization
功能完成后,通过发送电子邮件通知您的功能结果
frompynotice.mail.noticeimportnoticeOnFinishimportnumpyasnpsender="xxx@gmail.com"code="xxxxxxxxxxxxxxxx"# SMTP authorization code receiver="xxx@foxmail.com"# list or str# you can also send an attachments@noticeOnFinish(sender,code,receiver,attachments=['demo.txt'])deffoo(name="aaa"):x=np.array([[1,2,3],[2,3,4]])foriinrange(100):ifi%20==0:print(i)np.savetxt("demo.txt",x)returnx,[1,23,5,4],nameret=foo()print(ret)
当函数抛出异常时,通过电子邮件通知您异常情况
frompynotice.mail.noticeimportnoticeOnException,noticeOnFinishsender="xxx@qq.com"code="xxxxxxxxxxxxxxxx"# SMTP authorization code receiver="xxx@foxmail.com"# list or str@noticeOnFinish(sender,code,receiver,attachments=[])@noticeOnException(sender,code,receiver)deffoo(name="aaa"):return"ccc"re=foo()
包括
module | description |
---|---|
filetype | get the file format |
simpleaudio | play the wav audio |
zmail | send emails simply |
资源
模块中的两个wav声音是从here下载的。我以为我可以用ipad自己动手,但我是个新手,所以…