Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Jan 23, 2024
1 parent 6a5a173 commit 7a8e812
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
24 changes: 16 additions & 8 deletions projects/Organize_Directory/organizer.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -78,5 +85,6 @@ def main():
os.system("cls" if os.name == "nt" else "clear")
print("Finished organising your files")


if __name__ == "__main__":
main()
14 changes: 9 additions & 5 deletions projects/Rename_Images/rename_images.py
Original file line number Diff line number Diff line change
@@ -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()
16 changes: 10 additions & 6 deletions projects/Resize_Image/resize.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand All @@ -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()
25 changes: 13 additions & 12 deletions projects/what-for-dinner/main.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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.

0 comments on commit 7a8e812

Please sign in to comment.