Skip to content

gconsultz/Ubuntu_Requests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Outline:

  1. Ubuntu Image Fetcher (title & intro)

  2. Features

  3. 📂 Project Files

  4. Installation

  5. Usage

  6. Examples

  7. Ubuntu Principles

  8. Closing Note / License

Ubuntu Image Fetcher 🖼️

Description

This project is inspired by the Ubuntu philosophy:

"I am because we are."

The script connects to the wider web community by fetching images from the internet, saving them into an organized directory, and respecting community principles through safety checks, duplicate prevention, and graceful error handling.


Features

  • ✅ Fetch images from one or multiple URLs (comma-separated input or @urls.txt file)
  • ✅ Creates a Fetched_Images directory if it doesn’t exist
  • Checks HTTP headers (Content-Type, Content-Length, Content-Disposition) before saving
  • Prevents duplicate downloads by storing SHA-256 hashes in manifest.json
  • Safety precautions:
    • Only saves files with image/* Content-Type
    • Skips downloads larger than 10 MB (configurable in code)
    • Gracefully handles network and file errors
  • Organized & reusable — all metadata saved in manifest.json

📂 Project Files

  1. fetcher.py → Advanced version with:

Multiple URL support

HTTP header checks (Content-Type, Content-Length, Content-Disposition)

Duplicate detection using SHA-256 manifest (manifest.json)

Safe filenames & size limits

Clear error handling and console messages

  1. fetcher_backup.py → Minimal version that still meets assignment requirements:

Fetches images using requests

Handles HTTP errors with try/except

Creates Fetched_Images directory if missing

Extracts filename from URL or generates fallback

Saves image in binary mode

Skips duplicates if filename already exists

📝 Why Two Versions?

fetcher_backup.py proves I understood and implemented the core assignment requirements.

fetcher.py demonstrates going beyond the basics by adding robustness, safety, and Ubuntu principles in practice.

Requirements

  • Python 3.10+
  • Libraries:
    • requests

Install dependencies (inside a virtual environment recommended):

pip install requests


Setup & Usage

1. Clone or download this repository:

git clone https://github.com/yourusername/Ubuntu_Requests.git
cd Ubuntu_Requests

2. (Optional) Create and activate a virtual environment:

python -m venv venv
# Windows PowerShell
.\venv\Scripts\Activate.ps1

3. Install dependencies:

pip install -r requirements.txt


4. Run the script:

python fetcher.py


5. Enter one of the following when prompted:

A single URL

Multiple URLs separated by commas

@urls.txt to load URLs from a text file

Example (urls.txt content):

https://images.pexels.com/photos/414171/pexels-photo-414171.jpeg
https://picsum.photos/400/300


Example terminal output:

Welcome to the Ubuntu Image Fetcher (upgraded)
A tool for mindfully collecting images from the web

Enter image URLs (comma-separated) or '@urls.txt' to load from a file:
> @urls.txt

Fetching: https://images.pexels.com/photos/414171/pexels-photo-414171.jpeg
  - Content-Type: image/jpeg
  - Content-Length: 123456 bytes
✓ Successfully fetched: pexels-photo-414171.jpeg
✓ Image saved to Fetched_Images/pexels-photo-414171.jpeg

Fetching: https://picsum.photos/400/300
  - Content-Type: image/jpeg
✓ Successfully fetched: 400_300.jpg
✓ Image saved to Fetched_Images/400_300.jpg

Connection strengthened. Community enriched.


Ubuntu Principles Reflected

Community: Connects to global resources by fetching shared images

Respect: Gracefully handles errors and avoids unsafe downloads

Sharing: Organizes fetched images and metadata for later use

Practicality: Provides a simple, safe, reusable tool


Evaluation Criteria Checklist

✅ Proper use of the requests library

✅ Effective error handling for network issues

✅ Appropriate file management and directory creation

✅ Duplicate prevention implemented

✅ Clean, readable code with comments

✅ Faithfulness to Ubuntu principles


License

This project is for educational purposes under the PLP Academy assignment.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages