欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

分享五個(gè)超實(shí)用Python腳本,減少垃圾軟件負(fù)擔(dān)

 更新時(shí)間:2022年05月28日 11:06:44   作者:五包辣條!  
今天給大家?guī)?lái)幾個(gè)實(shí)用的python腳本工具,可以實(shí)現(xiàn)系統(tǒng)提示工具、文件夾清理工具等,這樣就再也不用擔(dān)心女朋友在電腦里安裝垃圾軟件啦

前言

大家好,我是辣條

今天給大家?guī)?lái)幾個(gè)實(shí)用的python腳本工具,原因不難猜這段時(shí)間我親愛的女朋友呢給我整出點(diǎn)小花樣,差點(diǎn)讓我電腦GG了。我打開系統(tǒng)盤一看真的是通紅通紅的啊 細(xì)細(xì)一看一堆的垃圾軟件,關(guān)鍵是她安裝的時(shí)候壓根不看附帶一堆的垃圾軟件,這時(shí)候我只能掏出我珍藏多年的一些腳本用以避免之后再發(fā)生類似的慘案了

系統(tǒng)提示工具

這個(gè)工具用到了win10toast庫(kù)來(lái)觸發(fā)系統(tǒng)的通知,可以用于提示重要事情。

#定時(shí)通知腳本
from win10toast import ToastNotifier
import time
#構(gòu)建通知對(duì)象實(shí)例
toaster = ToastNotifier()

title = input("請(qǐng)輸入事件標(biāo)題:")
content = input("請(qǐng)輸入事件提要")
time_min = float(input("請(qǐng)輸入提醒時(shí)間(分鐘):"))

#time_min = time_min * 60
print("設(shè)置完成!")
time.sleep(1)
print("開始運(yùn)行..")
time.sleep(time_min)
toaster.show_toast(f"{title}", f"{content}", duration=10, threaded=True)
while toaster.notification_active(): time.sleep(0.005)

文件夾清理工具

import os 
import threading 
import time 
  
  
def get_file_list(file_path): 
#文件按最后修改時(shí)間排序 
    dir_list = os.listdir(file_path) 
    if not dir_list: 
        return 
    else: 
        dir_list = sorted(dir_list, key=lambda x: os.path.getmtime(os.path.join(file_path, x))) 
    return dir_list 
  
def get_size(file_path): 
    """[summary] 
    Args: 
        file_path ([type]): [目錄] 
 
    Returns: 
        [type]: 返回目錄大小,MB 
    """ 
    totalsize=0 
    for filename in os.listdir(file_path): 
        totalsize=totalsize+os.path.getsize(os.path.join(file_path, filename)) 
    #print(totalsize / 1024 / 1024) 
    return totalsize / 1024 / 1024 
  
def detect_file_size(file_path, size_Max, size_Del): 
    """[summary] 
    Args: 
        file_path ([type]): [文件目錄] 
        size_Max ([type]): [文件夾最大大小] 
        size_Del ([type]): [超過(guò)size_Max時(shí)要?jiǎng)h除的大小] 
    """ 
    print(get_size(file_path)) 
    if get_size(file_path) > size_Max: 
        fileList = get_file_list(file_path) 
        for i in range(len(fileList)): 
            if get_size(file_path) > (size_Max - size_Del): 
                print ("del :%d %s" % (i + 1, fileList[i])) 
                #os.remove(file_path + fileList[i]) 
     
  
def detectFileSize(): 
 #檢測(cè)線程,每個(gè)5秒檢測(cè)一次 
    while True: 
        print('======detect============') 
        detect_file_size("/Users/aaron/Downloads/", 100, 30) 
        time.sleep(5) 
   
if __name__ == "__main__": 
    #創(chuàng)建檢測(cè)線程 
    detect_thread = threading.Thread(target = detectFileSize) 
    detect_thread.start()

PDF文件轉(zhuǎn)音頻

import pyttsx3
import pyPDF2

book = open('路徑/book.pdf',rb)
pdfreader = pyPDF2.PdfFileReader(book)
pages = pdfreader.numPages
print(pages)

voice = pyttsx3.init()
page = pdfreader.getpage(3)
text = page.extractText()
speaker.say(text)
speaker.runAndWait()

批量壓縮文件

import zipfile # zipfile庫(kù) 壓縮文件
import os
import time


def batch_zip(start_dir):
    start_dir = start_dir #文件路徑
    file_news = start_dir + '.zip' # 壓縮后文件夾的名字

    z = zipfile.ZipFile(file_news, 'w', zipfile.ZIP_DEFLATED)
    for dir_path, dir_names, file_names in os.walk(start_dir):
        #避免從根目錄復(fù)制
        f_path = dir_path.replace(start_dir, '')
        #壓縮所有文件
        f_path = f_path and f_path + os.sep
        for filename in file_names:
            z.write(os.path.join(dir_path, filename), f_path + filename)
     z.close()
     return file_news


batch_zip('./data/ziptest')

郵件發(fā)送

# 1、導(dǎo)入模塊
import yagmail

# 2、設(shè)置smtp服務(wù)信息
yag = yagmail.SMTP(user="改成自己的郵箱賬號(hào)@126.com", password="改成自己的郵箱密碼", host='smtp.126.com')

# 3、設(shè)置郵件主題與郵件內(nèi)容
subject = 'Python郵件測(cè)試'
content = ['Python郵件測(cè)試 -- 郵件來(lái)自黑馬程序員Python+大數(shù)據(jù)']

# 4、發(fā)送郵件
yag.send('gocndws@126.com', subject, content)

以上就是分享五個(gè)超實(shí)用Python腳本,減少垃圾軟件負(fù)擔(dān)的詳細(xì)內(nèi)容,更多關(guān)于Python腳本的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論