|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +import time |
| 4 | +from PIL import Image |
| 5 | + |
| 6 | + |
| 7 | +class Wallpaper: |
| 8 | + # Set Environment Variables |
| 9 | + username = os.environ['USERNAME'] |
| 10 | + |
| 11 | + # All file urls |
| 12 | + file_urls = { |
| 13 | + "wall_src": "C:\\Users\\" + username |
| 14 | + + "\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\" |
| 15 | + + "LocalState\\Assets\\", |
| 16 | + "wall_dst": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\", |
| 17 | + "wall_mobile": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\mobile\\", |
| 18 | + "wall_desktop": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\desktop\\" |
| 19 | + } |
| 20 | + msg = ''' |
| 21 | + DDDDD OOOOO NN N EEEEEEE |
| 22 | + D D O O N N N E |
| 23 | + D D O O N N N E |
| 24 | + D D O O N N N EEEE |
| 25 | + D D O O N N N E |
| 26 | + D D O O N N N E |
| 27 | + DDDDD OOOOO N NN EEEEEEE |
| 28 | + ''' |
| 29 | + |
| 30 | + # A method to showcase time effect |
| 31 | + @staticmethod |
| 32 | + def time_gap(string): |
| 33 | + print(string, end='') |
| 34 | + time.sleep(1) |
| 35 | + print(".", end='') |
| 36 | + time.sleep(1) |
| 37 | + print(".") |
| 38 | + |
| 39 | + # A method to import the wallpapers from src folder(dir_src) |
| 40 | + @staticmethod |
| 41 | + def copy_wallpapers(): |
| 42 | + w = Wallpaper |
| 43 | + w.time_gap("Copying Wallpapers") |
| 44 | + # Copy All Wallpapers From Src Folder To Dest Folder |
| 45 | + for filename in os.listdir(w.file_urls["wall_src"]): |
| 46 | + shutil.copy(w.file_urls["wall_src"] + filename, w.file_urls["wall_dst"]) |
| 47 | + |
| 48 | + # A method to Change all the Extensions |
| 49 | + @staticmethod |
| 50 | + def change_ext(): |
| 51 | + w = Wallpaper |
| 52 | + w.time_gap("Changing Extensions") |
| 53 | + # Look into all the files in the executing folder and change extension |
| 54 | + for filename in os.listdir(w.file_urls["wall_dst"]): |
| 55 | + base_file, ext = os.path.splitext(filename) |
| 56 | + if ext == "": |
| 57 | + if not os.path.isdir(w.file_urls["wall_dst"] + filename): |
| 58 | + os.rename(w.file_urls["wall_dst"] + filename, |
| 59 | + w.file_urls["wall_dst"] + filename + ".jpg") |
| 60 | + |
| 61 | + # Remove all files Not having Wallpaper Resolution |
| 62 | + @staticmethod |
| 63 | + def extract_wall(): |
| 64 | + w = Wallpaper |
| 65 | + w.time_gap("Extracting Wallpapers") |
| 66 | + for filename in os.listdir(w.file_urls["wall_dst"]): |
| 67 | + base_file, ext = os.path.splitext(filename) |
| 68 | + if ext == ".jpg": |
| 69 | + im = Image.open(w.file_urls["wall_dst"] + filename) |
| 70 | + if list(im.size)[0] != 1920 and list(im.size)[0] != 1080: |
| 71 | + im.close() |
| 72 | + os.remove(w.file_urls["wall_dst"] + filename) |
| 73 | + else: |
| 74 | + im.close() |
| 75 | + # Arrange the wallpapers into the corresponding folders |
| 76 | + @staticmethod |
| 77 | + def arr_desk_wallpapers(): |
| 78 | + w = Wallpaper |
| 79 | + w.time_gap("Arranging Desktop wallpapers") |
| 80 | + for filename in os.listdir(w.file_urls["wall_dst"]): |
| 81 | + base_file, ext = os.path.splitext(filename) |
| 82 | + if ext == ".jpg": |
| 83 | + try: |
| 84 | + im = Image.open(w.file_urls["wall_dst"] + filename) |
| 85 | + |
| 86 | + if list(im.size)[0] == 1920: |
| 87 | + im.close() |
| 88 | + os.rename(w.file_urls["wall_dst"] + filename, |
| 89 | + w.file_urls["wall_desktop"] + filename) |
| 90 | + if list(im.size)[0] == 1080: |
| 91 | + im.close() |
| 92 | + os.rename(w.file_urls["wall_dst"] + filename, |
| 93 | + w.file_urls["wall_mobile"] + filename) |
| 94 | + else: |
| 95 | + im.close() |
| 96 | + except FileExistsError: |
| 97 | + print("File Already Exists!") |
| 98 | + os.remove(w.file_urls["wall_dst"] + filename) |
| 99 | + |
| 100 | + @staticmethod |
| 101 | + def exec_all(): |
| 102 | + w = Wallpaper |
| 103 | + w.copy_wallpapers() |
| 104 | + w.change_ext() |
| 105 | + w.extract_wall() |
| 106 | + w.arr_desk_wallpapers() |
| 107 | + print(w.msg) |
| 108 | + time.sleep(3) |
| 109 | + |
| 110 | + |
| 111 | +wall = Wallpaper() |
| 112 | +wall.exec_all() |
0 commit comments