Metadata-Version: 2.1
Name: shiertier_scrapy
Version: 0.0.5
Summary: A simple scrapy library for Python.
Author-email: shiertier <junjie.text@gmail.com>
License: MIT License
        
        Copyright (c) 2024 shiertier
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: Pillow
Requires-Dist: tqdm
Requires-Dist: shiertier-logger

# shiertier_scrapy

English | [中文](https://github.com/shiertier-utils/shiertier_scrapy/blob/main/README_zh.md)

## Introduction

`shiertier_scrapy` is a Python library designed to simplify the process of downloading images from the web. It provides a robust and flexible interface for handling various HTTP status codes, retries, and image validation. This library is particularly useful for web scraping tasks where image downloads are required.

## Installation

You can install `shiertier_scrapy` via `pip`:

```bash
pip install git+https://github.com/shiertier-utils/shiertier_scrapy.git
```

Please note that this project is still under development.

## Environment Variables and Storage Location

### Environment Variables

- `SCRAPY_SAVE_DIR`: The directory where downloaded images will be saved. If not provided, the current working directory will be used.

### Setting the Storage Location

You can specify the storage location by setting the `SCRAPY_SAVE_DIR` environment variable:

```bash
export SCRAPY_SAVE_DIR=/path/to/save_directory
```

Alternatively, you can pass the `save_dir` parameter when initializing the `ScrapyClientBase` class:

```python
from shiertier_scrapy import ScrapyClientBase

# Initialize with a custom save directory
scrapy_client = ScrapyClientBase(save_dir='/path/to/save_directory')
```

## Usage

### Downloading a Single Image

You can download a single image using the `download_one` method. This method requires the URL of the image and the desired save name. It also supports retries and sleep time between retries.

```python
from shiertier_scrapy import easy_scrapy_client

# Download a single image
easy_scrapy_client.download_one(url='http://example.com/image.jpg', save_name='image.jpg')
```

### Downloading Multiple Images

You can download multiple images concurrently using the `download_images` method. This method requires a list of URLs and corresponding save names. It also supports retries and sleep time between retries.

```python
from shiertier_scrapy import easy_scrapy_client

# URLs and save names
urls = ['http://example.com/image1.jpg', 'http://example.com/image2.jpg']
save_names = ['image1.jpg', 'image2.jpg']

# Download multiple images
easy_scrapy_client.download_images(urls=urls, save_names=save_names)
```

## Dependencies

- `requests`
- `Pillow`
- `shiertier_logger`
- `tqdm`

## License

This project is released under the MIT License. See the [LICENSE](LICENSE) file for details.
