Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 7a8e812

Browse files
committed
Fix code style issues with Black
1 parent 6a5a173 commit 7a8e812

4 files changed

Lines changed: 48 additions & 31 deletions

File tree

projects/Organize_Directory/organizer.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
import os
22
import shutil
33

4+
45
def main():
56
dir_path = input("Enter the directory path of the files: ")
67

78
try:
8-
print("Organising your files into [ images - music - video - executable - archive - torrent - document - code - design files]")
9+
print(
10+
"Organising your files into [ images - music - video - executable - archive - torrent - document - code - design files]"
11+
)
912
for filename in os.listdir(dir_path):
1013
absname = os.path.join(dir_path, filename)
11-
# Check if files are images and you can add more extensions
12-
if filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm")):
14+
# Check if files are images and you can add more extensions
15+
if filename.lower().endswith(
16+
(".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm")
17+
):
1318
# If images folder doesn't exist then create new folder
1419
if not os.path.exists("images"):
1520
os.makedirs("images")
1621
shutil.move(absname, "images")
1722

1823
# Check if files are music and you can add more extensions
19-
elif filename.lower().endswith((".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw")):
24+
elif filename.lower().endswith(
25+
(".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw")
26+
):
2027
# If music folder doesn't exist then create new folder
2128
if not os.path.exists("music"):
2229
os.makedirs("music")
@@ -30,14 +37,14 @@ def main():
3037
shutil.move(absname, "video")
3138

3239
# Check if files are executables
33-
elif filename.lower().endswith((".exe", ".msi", ".deb" , "dmg")):
40+
elif filename.lower().endswith((".exe", ".msi", ".deb", "dmg")):
3441
# If executables folder doesn't exist then create new folder
3542
if not os.path.exists("executables"):
3643
os.makedirs("executables")
3744
shutil.move(absname, "executables")
3845

3946
# Check if files are archive files
40-
elif filename.lower().endswith((".rar", ".tar" , ".zip" , ".gz")):
47+
elif filename.lower().endswith((".rar", ".tar", ".zip", ".gz")):
4148
# If archive folder doesn't exist then create new folder
4249
if not os.path.exists("archives"):
4350
os.makedirs("archives")
@@ -51,14 +58,14 @@ def main():
5158
shutil.move(absname, "torrent")
5259

5360
# Check if files are documents
54-
elif filename.lower().endswith((".txt", ".pdf", ".docx" , "doc")):
61+
elif filename.lower().endswith((".txt", ".pdf", ".docx", "doc")):
5562
# If documents folder doesn't exist then create new folder
5663
if not os.path.exists("documents"):
5764
os.makedirs("documents")
5865
shutil.move(absname, "documents")
5966

6067
# Check if files are code files
61-
elif filename.lower().endswith((".py", ".php", ".html" , ".css" , ".js")):
68+
elif filename.lower().endswith((".py", ".php", ".html", ".css", ".js")):
6269
# If code folder doesn't exist then create new folder
6370
if not os.path.exists("code"):
6471
os.makedirs("code")
@@ -78,5 +85,6 @@ def main():
7885
os.system("cls" if os.name == "nt" else "clear")
7986
print("Finished organising your files")
8087

88+
8189
if __name__ == "__main__":
8290
main()
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
import os
22

3+
34
def main():
4-
img_types = ['jpg', 'png', 'jpeg']
5+
img_types = ["jpg", "png", "jpeg"]
56
dir_path = input("Enter the directory path of the images: ")
67

78
for i, f in enumerate(os.listdir(dir_path)):
89
absname = os.path.join(dir_path, f)
9-
img_type = absname.split('.')[-1]
10+
img_type = absname.split(".")[-1]
1011

1112
if img_type in img_types:
1213
while True:
1314
newname = input(f"Enter the new name for {f} (without extension): ")
14-
newname = '{}.{}'.format(newname, img_type)
15+
newname = "{}.{}".format(newname, img_type)
1516
new_absname = os.path.join(dir_path, newname)
1617
if not os.path.exists(new_absname):
1718
os.rename(absname, new_absname)
1819
break
1920
else:
20-
print("A file with this name already exists. Please enter a different name.")
21+
print(
22+
"A file with this name already exists. Please enter a different name."
23+
)
24+
25+
print("Done renaming images.")
2126

22-
print('Done renaming images.')
2327

2428
if __name__ == "__main__":
2529
main()

projects/Resize_Image/resize.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from PIL import Image
33

4+
45
def resize_image(image_path, size):
56
im = Image.open(image_path)
67
im = im.resize(size)
@@ -12,12 +13,12 @@ def main():
1213
width = int(input("Enter the width: "))
1314
height = int(input("Enter the height: "))
1415
size = (width, height)
15-
16+
1617
images = []
17-
if choice.lower() == 'yes':
18+
if choice.lower() == "yes":
1819
dir_path = input("Enter the directory path of the images: ")
1920
for filename in os.listdir(dir_path):
20-
if filename.endswith('.png') or filename.endswith('.jpg'):
21+
if filename.endswith(".png") or filename.endswith(".jpg"):
2122
image_path = os.path.join(dir_path, filename)
2223
images.append((image_path, resize_image(image_path, size)))
2324
else:
@@ -26,14 +27,17 @@ def main():
2627

2728
output_folder = input("Enter the output folder: ")
2829
os.makedirs(output_folder, exist_ok=True)
29-
30+
3031
for image_path, im in images:
31-
new_image_name = input(f"Enter the new name for {os.path.basename(image_path)}: ")
32+
new_image_name = input(
33+
f"Enter the new name for {os.path.basename(image_path)}: "
34+
)
3235
output_path = os.path.join(output_folder, new_image_name)
3336
im.save(output_path)
3437
print(f"Resized image is saved as {output_path}.")
3538

36-
print('Done resizing images.')
39+
print("Done resizing images.")
40+
3741

3842
if __name__ == "__main__":
3943
main()

projects/what-for-dinner/main.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
import requests # Import the 'requests' library for making HTTP requests.
1+
import requests # Import the 'requests' library for making HTTP requests.
2+
23

34
def main():
4-
menu_detail = dict(requests.get(
5-
"http://themealdb.com/api/json/v1/1/random.php"
6-
).json())["meals"][
5+
menu_detail = dict(
6+
requests.get("http://themealdb.com/api/json/v1/1/random.php").json()
7+
)["meals"][
78
0
8-
] # Extract the details of the first meal from the API response.
9+
] # Extract the details of the first meal from the API response.
910

1011
# TODO: Get information from the menu
1112
menu_name = menu_detail[
1213
"strMeal"
13-
] # Extract the name of the meal from the meal detail.
14+
] # Extract the name of the meal from the meal detail.
1415
menu_category = menu_detail[
1516
"strCategory"
16-
] # Extract the category of the meal from the meal detail.
17+
] # Extract the category of the meal from the meal detail.
1718
menu_tags = menu_detail[
1819
"strTags"
19-
] # Extract the tags (if available) of the meal from the meal detail.
20+
] # Extract the tags (if available) of the meal from the meal detail.
2021
menu_country = menu_detail[
2122
"strArea"
22-
] # Extract the country of the meal from the meal detail.
23+
] # Extract the country of the meal from the meal detail.
2324
menu_instruction = menu_detail[
2425
"strInstructions"
25-
] # Extract the cooking instructions of the meal.
26+
] # Extract the cooking instructions of the meal.
2627
menu_video = menu_detail[
2728
"strYoutube"
28-
] # Extract the YouTube video link for the meal (if available).
29+
] # Extract the YouTube video link for the meal (if available).
2930

3031
# TODO: Define color codes for printing colored output.
3132
class bcolors:
@@ -50,4 +51,4 @@ class bcolors:
5051

5152

5253
if __name__ == "__main__":
53-
main() # Call the main function when the script is executed as the main program.
54+
main() # Call the main function when the script is executed as the main program.

0 commit comments

Comments
 (0)