Skip to main content

Python Package to Download Images

Project description

Image Downloader

Python PyPI - Wheel PyPI - Downloads PyPI - License Read the Docs

PyPI text text

This is a Python Package called imagedownloader that defines three methods: fromList(), fromCsv(), and zipFolder(). The class is designed to download images from either a list of URLs or a CSV file containing multiple URLs, and then save them to a specified folder location. Additionally, it provides functionality to zip the folder where the downloaded images are saved.

The fromList() method takes a list of URLs and a folder path as arguments. If the specified folder does not exist, the method creates it. Then, it loops through the list of URLs, sends a request to download the image, and saves the image to the folder using the last part of the URL as the filename. If any errors occur during the process, the method prints an error message.

The fromCsv() method takes a CSV file path and a folder path as arguments. If the specified folder does not exist, the method creates it. Then, it reads the CSV file using the csv.reader() function and loops through each row. For each row, it extracts the URL, sends a request to download the image, and saves the image to the folder using the last part of the URL as the filename. If any errors occur during the process, the method prints an error message.

The zipFolder() method takes a folder path and an output path as arguments. It creates a new zip file at the output path and loops through each file in the specified folder using the os.walk() function. For each file, it adds the file to the zip file with the same filename. If any errors occur during the process, the method prints an error message.

The class also provides two dunder methods, str() and repr(), which return a string representation of the class instance.

Installation

Pytubev3 requires an installation of Python 3.7 or greater, as well as pip. (Pip is typically bundled with Python installations)

To install from PyPI with pip:

python -m pip install imgdownloader

Examples

CSV File Should have all the urls in the first column as follows


from imagedownloader import ImageDownloader

if __name__ == "__main__":
    
    image_urls = [
    'https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg',
    ]
    
    save_path = "./images"
    csv_path = "./test.csv"
    output_path = "./images.zip"
    folder_path = "./images"
    
    imgDownloader = ImageDownloader()
    imgDownloader.fromList(image_urls, save_path)
    imgDownloader.fromCsv(csv_path, save_path)
    imgDownloader.zipFolder(folder_path, output_path)

Development/Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add Some Feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.
  6. Email me at mazqoty.01@gmail.com because I do not check those messages often.

History

  • 1.0.3

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imagedownloader-1.0.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file imagedownloader-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for imagedownloader-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8931604d0945cd3f725287b2eccf6b000453ebf47e5d95d2d982c4c50192cdcf
MD5 01e8680f26c196fa6b2bf2192f9cb73f
BLAKE2b-256 183587bcf2dc7226cb994285b9b427072032de666d90c97633f35e63d13b3434

See more details on using hashes here.

Supported by

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