Windows 聚焦圖片會定期更新,拿來做壁紙不錯,它的目錄是:
%localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\
LocalState\Assets\
這里的檔案是沒有擴展名的,大于 100 KB 的就是圖片,可以直接復制出來加上 .jpg,
Python 代碼
import os
import shutil
# Windows Focus 圖片目錄
PATH = os.environ["LOCALAPPDATA"] + \
"/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets/"
# 圖片保存目錄
TARGET_PATH = "./Windows_Focus_Images/"
def get_windows_focus():
files = os.listdir(PATH)
os.makedirs(TARGET_PATH, exist_ok=True)
for file in files:
if os.path.getsize(PATH + file) / 1024 > 150:
# 復制檔案并加上擴展名
shutil.copy(PATH + file, TARGET_PATH + file + '.jpg')
if __name__ == "__main__":
get_windows_focus()
像 %localappdata% 這種變數在 Windows 資源管理器中可以被識別,但是在 Python 中不能,需要用 os.environ() 函式來獲取,將 % 去掉全部改為大寫即可,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/107606.html
標籤:其他
