• 使用 Python 获取 Windows 聚焦图片


    Windows 聚焦图片会定期更新,拿来做壁纸不错,它的目录是:

    %localappdata%PackagesMicrosoft.Windows.ContentDeliveryManager_cw5n1h2txyewy
    LocalStateAssets
    

    这里的文件是没有扩展名的,大于 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() 函数来获取,将 % 去掉全部改为大写即可。

  • 相关阅读:
    tomcat的安装以及环境配置
    MySQL日期/时间函数
    docker部署tomcat
    Lambda的高级查询
    Linq的使用
    多线程编程
    反射
    匿名类型
    委托和事件
    泛型特性
  • 原文地址:https://www.cnblogs.com/cloudfloating/p/11856612.html
Copyright © 2020-2023  润新知