Skip to content

Commit 6a8db34

Browse files
authored
refactor: improve code structure with response validation function
Refactored the script to improve modularity and readability. - Moved image validation logic to a separate function `is_valid_image_response` - Keeps `fetch_image` function focused on download and file saving - Prepares the script for future enhancements and better testability
1 parent cce04b5 commit 6a8db34

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ubuntu_image_fetcher.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,19 @@ def fetch_image(image_url):
4343
except requests.exceptions.RequestException as e:
4444
print(f"✗ Failed to fetch image: {e}")
4545
except Exception as e:
46-
print(f"✗ Un
46+
print(f"✗ Unexpected error: {e}")
47+
48+
def main():
49+
print("Welcome to the Ubuntu Image Fetcher")
50+
print("A tool for mindfully collecting images from the web\n")
51+
52+
urls_input = input("Please enter image URLs separated by commas: ")
53+
image_urls = [url.strip() for url in urls_input.split(",")]
54+
55+
os.makedirs("Fetched_Images", exist_ok=True)
56+
57+
for url in image_urls:
58+
fetch_image(url)
59+
60+
if __name__ == "__main__":
61+
main()

0 commit comments

Comments
 (0)