Windows 聚焦图片会按期更新,拿来作壁纸不错,它的目录是:python
%localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\ LocalState\Assets\
这里的文件是没有扩展名的,大于 100 KB 的就是图片,能够直接复制出来加上 .jpg
。windows
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()
函数来获取,将 %
去掉所有改成大写便可。app