Skip to content

A Python program that respectfully connects to the global web community to fetch and organize images while emphasizing community, respect, sharing, and practicality

License

Notifications You must be signed in to change notification settings

Mayen007/Ubuntu_Requests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ubuntu Image Fetcher 🐧

"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.

✨ Features

  • Single & Batch Downloads: Download individual images or process multiple URLs
  • Smart Organization: Auto-creates Fetched_Images directory 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

πŸš€ Quick Start

Prerequisites

  • Python 3.6+
  • Internet connection

Installation

  1. Clone or download the project

    git clone https://github.com/Mayen007/Ubuntu_Requests
    cd Ubuntu_Requests
  2. Install dependencies

   pip install -r requirements.txt
  1. Run the application
    python index.py

πŸ’» Usage

Interactive Mode

Run the program and choose your approach:

python index.py

Option 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

Example Session

🐧 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!

πŸ—οΈ Architecture

Core Class: UbuntuImageFetcher

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 summary

Key Methods

  • fetch_image(url): Downloads single image with full error handling
  • fetch_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

πŸ›‘οΈ Security Features

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

🌐 Ubuntu Principles Implementation

🀝 Community

  • Connects respectfully to global web resources
  • Uses proper User-Agent identification
  • Enables sharing through organized directory structure

πŸ™ Respect

  • 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)

πŸ“€ Sharing

  • Organized directory structure for easy sharing
  • Prevents duplicate downloads to save space
  • Clear feedback and operation summaries
  • Batch processing for efficient operations

πŸ”§ Practicality

  • Real-world error handling for network issues
  • Multiple image format support
  • User-friendly interface with clear prompts
  • Production-ready security features

πŸ“ Project Structure

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)

πŸ”§ Dependencies

certifi==2025.8.3
charset-normalizer==3.4.3
idna==3.10
requests==2.32.5
urllib3==2.5.0

❌ Error Handling

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

🎯 Requirements Met

βœ… Core Requirements:

  • Prompts user for image URL
  • Creates "Fetched_Images" directory using os.makedirs(exist_ok=True)
  • Downloads images using requests library
  • 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)

πŸš€ Advanced Usage

Programmatic Usage

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)

πŸ“Š Performance

  • 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

🀝 Contributing

This project embodies the Ubuntu philosophy of community collaboration. Contributions that enhance any of the four principles (Community, Respect, Sharing, Practicality) are welcome!

πŸ“„ License

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"

About

A Python program that respectfully connects to the global web community to fetch and organize images while emphasizing community, respect, sharing, and practicality

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages