diff --git a/projects/Organize_Directory/organizer.py b/projects/Organize_Directory/organizer.py index cb60ae46..6232baf2 100644 --- a/projects/Organize_Directory/organizer.py +++ b/projects/Organize_Directory/organizer.py @@ -1,22 +1,29 @@ import os import shutil + def main(): dir_path = input("Enter the directory path of the files: ") try: - print("Organising your files into [ images - music - video - executable - archive - torrent - document - code - design files]") + print( + "Organising your files into [ images - music - video - executable - archive - torrent - document - code - design files]" + ) for filename in os.listdir(dir_path): absname = os.path.join(dir_path, filename) - # Check if files are images and you can add more extensions - if filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm")): + # Check if files are images and you can add more extensions + if filename.lower().endswith( + (".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm") + ): # If images folder doesn't exist then create new folder if not os.path.exists("images"): os.makedirs("images") shutil.move(absname, "images") # Check if files are music and you can add more extensions - elif filename.lower().endswith((".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw")): + elif filename.lower().endswith( + (".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw") + ): # If music folder doesn't exist then create new folder if not os.path.exists("music"): os.makedirs("music") @@ -30,14 +37,14 @@ def main(): shutil.move(absname, "video") # Check if files are executables - elif filename.lower().endswith((".exe", ".msi", ".deb" , "dmg")): + elif filename.lower().endswith((".exe", ".msi", ".deb", "dmg")): # If executables folder doesn't exist then create new folder if not os.path.exists("executables"): os.makedirs("executables") shutil.move(absname, "executables") # Check if files are archive files - elif filename.lower().endswith((".rar", ".tar" , ".zip" , ".gz")): + elif filename.lower().endswith((".rar", ".tar", ".zip", ".gz")): # If archive folder doesn't exist then create new folder if not os.path.exists("archives"): os.makedirs("archives") @@ -51,14 +58,14 @@ def main(): shutil.move(absname, "torrent") # Check if files are documents - elif filename.lower().endswith((".txt", ".pdf", ".docx" , "doc")): + elif filename.lower().endswith((".txt", ".pdf", ".docx", "doc")): # If documents folder doesn't exist then create new folder if not os.path.exists("documents"): os.makedirs("documents") shutil.move(absname, "documents") # Check if files are code files - elif filename.lower().endswith((".py", ".php", ".html" , ".css" , ".js")): + elif filename.lower().endswith((".py", ".php", ".html", ".css", ".js")): # If code folder doesn't exist then create new folder if not os.path.exists("code"): os.makedirs("code") @@ -78,5 +85,6 @@ def main(): os.system("cls" if os.name == "nt" else "clear") print("Finished organising your files") + if __name__ == "__main__": main() diff --git a/projects/Rename_Images/rename_images.py b/projects/Rename_Images/rename_images.py index e813d57a..5b218bbb 100644 --- a/projects/Rename_Images/rename_images.py +++ b/projects/Rename_Images/rename_images.py @@ -1,25 +1,29 @@ import os + def main(): - img_types = ['jpg', 'png', 'jpeg'] + img_types = ["jpg", "png", "jpeg"] dir_path = input("Enter the directory path of the images: ") for i, f in enumerate(os.listdir(dir_path)): absname = os.path.join(dir_path, f) - img_type = absname.split('.')[-1] + img_type = absname.split(".")[-1] if img_type in img_types: while True: newname = input(f"Enter the new name for {f} (without extension): ") - newname = '{}.{}'.format(newname, img_type) + newname = "{}.{}".format(newname, img_type) new_absname = os.path.join(dir_path, newname) if not os.path.exists(new_absname): os.rename(absname, new_absname) break else: - print("A file with this name already exists. Please enter a different name.") + print( + "A file with this name already exists. Please enter a different name." + ) + + print("Done renaming images.") - print('Done renaming images.') if __name__ == "__main__": main() diff --git a/projects/Resize_Image/resize.py b/projects/Resize_Image/resize.py index bb7a8a00..956210ec 100644 --- a/projects/Resize_Image/resize.py +++ b/projects/Resize_Image/resize.py @@ -1,6 +1,7 @@ import os from PIL import Image + def resize_image(image_path, size): im = Image.open(image_path) im = im.resize(size) @@ -12,12 +13,12 @@ def main(): width = int(input("Enter the width: ")) height = int(input("Enter the height: ")) size = (width, height) - + images = [] - if choice.lower() == 'yes': + if choice.lower() == "yes": dir_path = input("Enter the directory path of the images: ") for filename in os.listdir(dir_path): - if filename.endswith('.png') or filename.endswith('.jpg'): + if filename.endswith(".png") or filename.endswith(".jpg"): image_path = os.path.join(dir_path, filename) images.append((image_path, resize_image(image_path, size))) else: @@ -26,14 +27,17 @@ def main(): output_folder = input("Enter the output folder: ") os.makedirs(output_folder, exist_ok=True) - + for image_path, im in images: - new_image_name = input(f"Enter the new name for {os.path.basename(image_path)}: ") + new_image_name = input( + f"Enter the new name for {os.path.basename(image_path)}: " + ) output_path = os.path.join(output_folder, new_image_name) im.save(output_path) print(f"Resized image is saved as {output_path}.") - print('Done resizing images.') + print("Done resizing images.") + if __name__ == "__main__": main() diff --git a/projects/what-for-dinner/main.py b/projects/what-for-dinner/main.py index 52f5e50d..2322b6eb 100644 --- a/projects/what-for-dinner/main.py +++ b/projects/what-for-dinner/main.py @@ -1,31 +1,32 @@ -import requests # Import the 'requests' library for making HTTP requests. +import requests # Import the 'requests' library for making HTTP requests. + def main(): - menu_detail = dict(requests.get( - "http://themealdb.com/api/json/v1/1/random.php" - ).json())["meals"][ + menu_detail = dict( + requests.get("http://themealdb.com/api/json/v1/1/random.php").json() + )["meals"][ 0 - ] # Extract the details of the first meal from the API response. + ] # Extract the details of the first meal from the API response. # TODO: Get information from the menu menu_name = menu_detail[ "strMeal" - ] # Extract the name of the meal from the meal detail. + ] # Extract the name of the meal from the meal detail. menu_category = menu_detail[ "strCategory" - ] # Extract the category of the meal from the meal detail. + ] # Extract the category of the meal from the meal detail. menu_tags = menu_detail[ "strTags" - ] # Extract the tags (if available) of the meal from the meal detail. + ] # Extract the tags (if available) of the meal from the meal detail. menu_country = menu_detail[ "strArea" - ] # Extract the country of the meal from the meal detail. + ] # Extract the country of the meal from the meal detail. menu_instruction = menu_detail[ "strInstructions" - ] # Extract the cooking instructions of the meal. + ] # Extract the cooking instructions of the meal. menu_video = menu_detail[ "strYoutube" - ] # Extract the YouTube video link for the meal (if available). + ] # Extract the YouTube video link for the meal (if available). # TODO: Define color codes for printing colored output. class bcolors: @@ -50,4 +51,4 @@ class bcolors: if __name__ == "__main__": - main() # Call the main function when the script is executed as the main program. + main() # Call the main function when the script is executed as the main program.