"I am because we are" - A Python image downloader embodying Ubuntu philosophy
Power Learn Project - Python Week 6 Assignment
Libraries and File Handling Assignment
A Python application that respectfully connects to the global web community to fetch and organize images while emphasizing community, respect, sharing, and practicality.
- Single & Batch Downloads: Download individual images or process multiple URLs
- Smart Organization: Auto-creates
Fetched_Imagesdirectory with organized storage - Duplicate Prevention: MD5 hash-based detection prevents redundant downloads
- Security Focused: Validates file types, implements size limits, and safe filename generation
- Graceful Error Handling: Never crashes, provides helpful feedback for all scenarios
- Ubuntu Philosophy: Every feature designed around community, respect, sharing, and practicality
- Python 3.6+
- Internet connection
-
Clone or download the project
git clone https://github.com/Mayen007/Ubuntu_Requests cd Ubuntu_Requests -
Install dependencies
pip install -r requirements.txt- Run the application
python index.py
Run the program and choose your approach:
python index.pyOption 1 - Single Image:
- Enter one image URL
- Image downloads to
Fetched_Images/directory
Option 2 - Multiple Images:
- Enter URLs one per line
- Press Enter on empty line to start batch download
- View summary report when complete
π§ Ubuntu Image Fetcher
==================================================
Connecting communities through shared visual resources
Principles: Community β’ Respect β’ Sharing β’ Practicality
==================================================
Choose your approach:
1. Fetch a single image
2. Fetch multiple images
Enter your choice (1 or 2): 1
π Please enter the image URL: https://example.com/image.jpg
π Connecting to: https://example.com/image.jpg
β
Successfully saved: image.jpg (245.3KB)
π Saved to: Fetched_Images\image.jpg
π Ubuntu spirit: Through sharing, we build community!
class UbuntuImageFetcher:
def __init__(self, directory="Fetched_Images")
def fetch_image(self, url) # Download single image
def fetch_multiple_images(self, urls) # Batch download
def display_summary(self, results) # Show operation summaryfetch_image(url): Downloads single image with full error handlingfetch_multiple_images(urls): Processes multiple URLs with progress tracking_is_safe_content_type(): Validates image file types for security_check_duplicate(): Prevents duplicate downloads using MD5 hashing_generate_filename(): Creates appropriate filenames from URLs
| Feature | Description |
|---|---|
| Content Validation | Only downloads verified image formats (JPEG, PNG, GIF, WebP, BMP, SVG) |
| Size Limits | 50MB maximum file size to prevent abuse |
| Safe Filenames | Secure, filesystem-friendly filename generation |
| Timeout Protection | Network timeouts prevent hanging connections |
| Header Validation | Checks HTTP headers before downloading |
- Connects respectfully to global web resources
- Uses proper User-Agent identification
- Enables sharing through organized directory structure
- Graceful error handling - never crashes
- Bandwidth conscious with size limits and delays
- Respects server responses and HTTP status codes
- Polite request patterns (HEAD requests first)
- Organized directory structure for easy sharing
- Prevents duplicate downloads to save space
- Clear feedback and operation summaries
- Batch processing for efficient operations
- Real-world error handling for network issues
- Multiple image format support
- User-friendly interface with clear prompts
- Production-ready security features
Ubuntu_Requests/
βββ index.py # Main Ubuntu Image Fetcher application
βββ requirements.txt # Python dependencies
βββ LICENSE # License file
βββ Fetched_Images/ # Created automatically for downloaded images
βββ venv/ # Virtual environment (recommended)
certifi==2025.8.3
charset-normalizer==3.4.3
idna==3.10
requests==2.32.5
urllib3==2.5.0
The application gracefully handles:
- Network Issues: Connection timeouts, DNS failures
- HTTP Errors: 404 Not Found, 403 Forbidden, 500 Server Error
- Invalid Content: Non-image URLs, corrupted files
- File System: Permission issues, disk space problems
- Security: Malicious URLs, oversized files
β Core Requirements:
- Prompts user for image URL
- Creates "Fetched_Images" directory using
os.makedirs(exist_ok=True) - Downloads images using
requestslibrary - Handles HTTP errors appropriately
- Extracts filenames from URLs or generates appropriate ones
- Saves images in binary mode
β Challenge Questions:
- Multiple URL support with batch processing
- Security precautions for unknown sources
- Duplicate prevention using MD5 hashing
- HTTP header validation (Content-Type, Content-Length)
from index import UbuntuImageFetcher
# Initialize fetcher
fetcher = UbuntuImageFetcher("MyImages")
# Download single image
success, message, filepath = fetcher.fetch_image("https://example.com/image.jpg")
print(message)
# Batch download
urls = ["https://site1.com/img1.jpg", "https://site2.com/img2.png"]
results = fetcher.fetch_multiple_images(urls)
fetcher.display_summary(results)- Memory Efficient: Streams large files instead of loading into memory
- Bandwidth Conscious: Respects server resources with delays and limits
- Fast Duplicate Detection: Hash-based comparison for quick duplicate prevention
- Concurrent Safe: Thread-safe design for future enhancement
This project embodies the Ubuntu philosophy of community collaboration. Contributions that enhance any of the four principles (Community, Respect, Sharing, Practicality) are welcome!
Open source in the spirit of Ubuntu - shared knowledge benefits everyone.
Ubuntu Image Fetcher - Connecting communities through shared visual resources
"Through code, we build bridges between communities"