Python調(diào)用win10toast框架實(shí)現(xiàn)定時調(diào)起系統(tǒng)通知
前言
win10toast是一個windows通知的出發(fā)框架,使用它可以輕松的調(diào)起系統(tǒng)通知。通過它可以很方便的做一個定時通知的功能應(yīng)用。
實(shí)現(xiàn)步驟
安裝調(diào)起通知的依賴庫
pip install win10toast
導(dǎo)入相關(guān)的第三方依賴庫
from win10toast import ToastNotifier # 導(dǎo)入系統(tǒng)通知對象 import time # 系統(tǒng)時間模塊 import datetime from threading import Timer # 定時器
初始化通知調(diào)用對象
notify = ToastNotifier() # 初始化系統(tǒng)通知對象
初始化windows通知相關(guān)的參數(shù),設(shè)置定時通知間隔時間等。
notify_head = '主人,來通知啦!' notify_min = 1.0 notify_text = '已經(jīng)過了' + str(int(notify_min)) + '分鐘了,該喝水了!' notify_sen = notify_min * 1
通知調(diào)起時,是使用win10toast的show_toast()函數(shù),參數(shù)和定義如下面。
''' def show_toast(self, title="Notification", msg="Here comes the message", icon_path=None, duration=5, threaded=False): """Notification settings. :title: notification title :msg: notification message :icon_path: path to the .ico file to custom notification :duration: delay in seconds before notification self-destruction """ '''
show_toast()函數(shù)的使用,采用timer定時器來定時的調(diào)起應(yīng)用發(fā)送通知。
def show_toast(): print('當(dāng)前時間:%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) notify.show_toast(f"{notify_head}", f"{notify_text}", duration=5, threaded=True, icon_path='水杯.ico') while notify.notification_active(): time.sleep(0.005) timer = Timer(notify_sen, show_toast) timer.start()
主函數(shù)入口調(diào)用。
if __name__ == '__main__': show_toast()
補(bǔ)充
Win10 沒有提供簡單命令行方式來觸發(fā)桌面通知,所以只能使用Python來寫通知腳本。
一番搜索,找到 win10toast 。但這開源倉庫已無人維護(hù),通過 github fork 的關(guān)系圖,找到 win10toast-click,一個正在更新功能更全的 Python 第三方模塊。
使用與場景
qBittorrent 支持下載完成后運(yùn)行外部程序,由于 qBittorrent 沒有下載完成后桌面通知的功能,所以我們通過Python腳本來完成。
通過 win10toast-click
倉庫中示例,就可以完成一個簡單的通知腳本。
import argparse from win10toast_click import ToastNotifier parser = argparse.ArgumentParser() parser.add_argument('--title', help='通知標(biāo)題') parser.add_argument('--message', help='通知內(nèi)容') args = parser.parse_args() toaster = ToastNotifier() toaster.show_toast(title=args.title, msg=args.message)
qBittorrent 提供了一些參數(shù)可以傳遞給調(diào)用程序,使用 argparse
內(nèi)建模塊來接收。
qBittorrent 運(yùn)行外部程序
python <腳本路徑>/qb_win_toast.py --title "下載完成" --message "%N 下載完成"
到此這篇關(guān)于Python調(diào)用win10toast框架實(shí)現(xiàn)定時調(diào)起系統(tǒng)通知的文章就介紹到這了,更多相關(guān)Python win10toast調(diào)起系統(tǒng)通知內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Tensorflow 自定義loss的情況下初始化部分變量方式
今天小編就為大家分享一篇Tensorflow 自定義loss的情況下初始化部分變量方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01django中send_mail功能實(shí)現(xiàn)詳解
這篇文章主要給大家介紹了關(guān)于django中send_mail功能實(shí)現(xiàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-02-02Centos7 Python3下安裝scrapy的詳細(xì)步驟
這篇文章主要介紹了Centos7 Python3下安裝scrapy的詳細(xì)步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03python進(jìn)度條庫tqdm使用記錄(特點(diǎn)和用法)
tqdm是一個Python庫,用于在命令行界面中創(chuàng)建美觀的進(jìn)度條,以跟蹤代碼中循環(huán)、迭代和任務(wù)的執(zhí)行進(jìn)度,本文給大家介紹python進(jìn)度條庫tqdm使用記錄,感興趣的朋友跟隨小編一起看看吧2023-10-10Pycharm+Flask零基礎(chǔ)項(xiàng)目搭建入門的實(shí)現(xiàn)
本文主要介紹了Pycharm+Flask零基礎(chǔ)項(xiàng)目搭建入門的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04