Skip to main content

No project description provided

Project description

afetchx

Asynchronously fetch image URLs using httpx.

afetchx parses command-line arguments to determine the list of image URLs to fetch, the maximum number of concurrent connections, the cooldown time between requests, an optional JSON file containing URLs, and output options. It then fetches the images, saves them in the specified output directory, and prints the number of successfully downloaded images.

Usage

Invoke the script with

python -m afetchx {args}

Command-line arguments

  • -n, --max_connections: Max number of concurrent connections (default: 5).
  • -c, --cooldown: Cooldown time between requests in seconds (default: 1.0).
  • -j, --json: Path to a JSON file containing URLs to fetch.
  • -o, --output-dir: Directory to save downloaded images (default: ./downloaded in the current working directory).
  • --filename-format: Lambda function as a string to format filenames based on the URL (e.g., "lambda url: url.split('/')[-1].split('.')[0] + '.png'").
  • urls: List of image URLs to fetch (positional arguments).

Note: You must satisfy exactly one of the following conditions

  1. Use the --json (-j) argument to specify a JSON file containing URLs.
  2. Provide one or more URLs directly as positional arguments.

Examples

Basic Usage

Download images from a JSON file with a cooldown of 1 second between each download and a maximum of 5 concurrent connections:

python -m afetchx -j urls.json -c 1.0 -n 5

Specify Output Directory

Download images from URLs provided as positional arguments and save them to a custom directory:

python -m afetchx -c 1.0 -n 5 -o ./downloaded_pictures "https://unsplash.it/256.jpg" "https://unsplash.it/512.jpg"

Use Custom Filename Format

Download images and apply a custom filename format based on the URL:

python -m afetchx -c 1.0 -n 5 --filename-format "lambda url: url.split('/')[-1].split('.')[0] + '.png'" "https://example.com/image1.png" "https://example.com/image2.jpg"

In this example, each downloaded image will be named according to the lambda function. The filename format option can be especially useful for sanitizing or modifying filenames before saving.

Error Handling

If both URLs and a JSON file are provided, the script will print an error and exit. Likewise, if neither URLs nor a JSON file are provided, the script will print an error and exit. Ensure exactly one source for URLs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afetchx-1.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

afetchx-1.1.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file afetchx-1.1.1.tar.gz.

File metadata

  • Download URL: afetchx-1.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Windows/11

File hashes

Hashes for afetchx-1.1.1.tar.gz
Algorithm Hash digest
SHA256 9bf1db1d78be4ca8e99ee628cb5c29211a0b2ee7237f7093d467e88d9db1522c
MD5 0636390ba8925834b14edd6fdccac8fd
BLAKE2b-256 dadfb305a295265cbf478bb1d3ef23444a8800e2a5e88160fb27bfcbd8142012

See more details on using hashes here.

File details

Details for the file afetchx-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: afetchx-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Windows/11

File hashes

Hashes for afetchx-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cfe72b57997097a230eea343e9743c95fd057146d1003e804d2e0329da6c6f3
MD5 b16b4583a7fd9ba0e478b8b0ad4dc9b8
BLAKE2b-256 de41505979237faa9925852a8a176cb310560fda2b221980c962173c39da3628

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page