Python | How to download windows lock-screen wallpapers

Have you ever seen these cool wallpaper in your Windows 10 Lock Screen, whenever you open your PC/Laptop?
Wallpaper

Whenever we are connected to the internet, they are going to change randomly. But ever wondered the working behind it? Well, those images are stored in the following path:

C:\Users\[[Your Username]]\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets

But there is a twist in the tale. The wallpapers are going to look like this.
Screenshot
These are actually the images without their extensions, that is their extension is removed.

You might be thinking of copying the images one by one and then changing the extension of the image one by one, and that too manually.
Well, to make your life easier, Python is there for you. It will do the task just for you, that too with a single code.

Below is the Python implementation –

Note: Make a folder named WALLPAPER on the Desktop.

filter_none

edit
close

play_arrow

link
brightness_4
code

import os
import shutil
  
os.chdir('C:\\')
username = os.environ['USERNAME']
  
# The folder which contains the wallpaper files
source = ("C:\\Users\\"+ username +"\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets\\")
  
# You will have to add the path of your
# destination here. Just make sure the
# folder exists on the desktop.
destination = ("C:\\Users\\"+ username +"\\Desktop\\WALLPAPER\\")
  
for the_file in os.listdir(destination):
      
    path_of_file = os.path.join(destination, the_file)
    base_file, ext = os.path.splitext(the_file)
  
    if ext ==".jpg":
        try:
            if os.path.isfile(path_of_file):
                os.unlink(path_of_file)
  
        except Exception as e:
            print(e)
              
for name_of_file in os.listdir(source):
    shutil.copy( source + name_of_file, destination)
    print(name_of_file)

chevron_right


But still, the folder will look like this.
Folder1

So what to do next?
See the below Python code, save it as a copy in the same WALLPAPER folder on the desktop and RUN IT there.

Below is the Python code –

filter_none

edit
close

play_arrow

link
brightness_4
code

import os, sys
  
# It oversees all the file in the folder 
# and changes it with a proper extension.
for filename in os.listdir(os.path.dirname(os.path.abspath(__file__))):
    
  base_file, ext = os.path.splitext(filename)
    
  if ext == "":
    os.rename(filename, base_file + ".jpg")

chevron_right


After execution, the folder will look like this. There will be a few images which will not be a wallpaper but instead will be an icon for some games or other applications. But once you delete them, you will get a cool folder full of cool wallpapers.
FINAL



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

4


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.