Python Tools Series – 1

Python Tools Series - 1

Are you new to python? Are you looking for some free cool python tool?

If yes, then you are on the right page 👍

In this article series I am going to discuss exactly, what you are looking for.

Python is one of most popular programming language in the world. Everyday, more and more people are using python for solving simple real-life problems.

Look at the python popularity at the moment. The PYPL site has ranked python at number one place in terms of popularity.

source: PYPL

There are several other online resources, where you can get theoretical knowledge about Python. In fact, there are official website for python and also vibrant community.

However, there are not many resources where you get a ready-made python tool that exactly solves your problem domain. I have been using Python for the last 8+ years and have developed various tools to solve real-life problems. So, I am going to share those python tools with you and also explain to you how these tools work.

Problem Domain

There is a lot of time when I wanted to download a bunch of photos one by one. I had 100 different image URLs and I had to download them one by one.

Imagine copying 100 URLs one by one and then paste them in the browser and then downloading them and naming them sequentially. Definitely, it’s a time-consuming task.

Can you automate it using python? Absolutely, YES! 💪👍

I just written a couple of lines of code that probably saved 15-20 minutes of my life! Of course, writing the tools will take time, but, hey, that’s only for the first time. From the second time onwards, you are just gonna run the tool and save your time.

Since I have already built the tool, and I am gonna share with you, you don’t have the spend the time to create the tool.

If you got the same problem, you are just gonna download the file and execute it!

List of the Image URLs, I wanted to Download

I am not going to share the whole list of 100 URLs that I wanted to download. Rather, I am just sharing the three sample image URLs that I am considering to demonstrate this tool.

  1. https://bit.ly/2SLa41A
  2. https://bit.ly/3iHH3ys
  3. https://bit.ly/3dkrWd9

Of course, I have shorten these links for easy usage.

What I want to Automate

I want to download these links automatically through a python script. So, I will run a python tool that will download all these three files for me. I don’t have to open these URLs manually and download them.

Python Tool

Here the python that I used to automate this task:

# Importing all the required modules
import urllib.request

# Image URL List
filename = ''
Image_URL_List = [ "https://bit.ly/2SLa41A",
                   "https://bit.ly/3iHH3ys",
                   "https://bit.ly/3dkrWd9"]

counter = 1
for each_url in Image_URL_List:
    filename = str(counter) + '.jpg'
    print(filename)

    # Download each image url
    urllib.request.urlretrieve(each_url, filename)

    counter = counter + 1
                   

As you can see, by using these 9 lines of python code, you can automatically download as many images as you want automatically.

So, in your case, if you want to download 50 images, you need to collect the URLs and update the “Image_URL_List” variable in the above program at Line Number 6. Then you can execute the program and all your 50 images will be downloaded and saved in your current directory from where you are executing the python program.

Python Tool Output

Here is the output of the python tool:

Python Tool Output
Tool Output

Here, you can see that I got the three images downloaded and they are named as “1.jpg”, “2.jpg”, “3.jpg”. You get the file saved in the same order as you mention the URLs in the “Image_URL_List” variable.

How the Tool is working

The working principle of the tool is very simple. It imports the urllib package which helps us with the downloading part.

It then loops through each image URL at a time and download them by using the urlretrieve() function in urllib package.

By the way, I am planning to improve the tool by adding a file read function which allow us to just put all the URL links in a text file and then run the tool. This would be much more easier to use for sure.

Can I download image as PNG instead of JPG format?

Definitely. You just need to change the extension at Line number 12.

Download The Tool

You can download the python tool by Clicking Here.

Summary

Python is a well known and very popular programming language at the moment all over the world.

Today, in this article – Python Tools Series – 1, I have explained step-by-step, how to create a python script/tool to download 100/1000 of images at one go. If you have 10,000 images to download, you can just run the tool and go for a coffee break 😉

If you have any questions, please feel free to comment in the comment box below 👇👇👇

In the next series, I will share some other tool which might be useful for solving your real-life problems.

Stay Tuned!

Python Tools Series – 1

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top
error: