Sunday, April 20, 2025

Script to download images from a website using popular libraries.

 Python3.12 Version


import requests

from bs4 import BeautifulSoup

import os

from urllib.parse import urljoin, urlparse

import asyncio

import aiohttp

import aiofiles


async def download_image(session, url, folder):

    """Download a single image asynchronously"""

    # Create a valid filename from the URL

    filename = os.path.join(folder, os.path.basename(urlparse(url).path))

    

    # Skip if file exists

    if os.path.exists(filename):

        print(f"Skipping existing file: {filename}")

        return

    

    try:

        async with session.get(url) as response:

            if response.status == 200:

                # Ensure the filename has an extension

                if not os.path.splitext(filename)[1]:

                    content_type = response.headers.get('Content-Type', '')

                    if 'jpeg' in content_type or 'jpg' in content_type:

                        filename += '.jpg'

                    elif 'png' in content_type:

                        filename += '.png'

                    elif 'gif' in content_type:

                        filename += '.gif'

                    elif 'webp' in content_type:

                        filename += '.webp'

                    else:

                        filename += '.jpg'  # Default extension

                

                # Save the image

                async with aiofiles.open(filename, 'wb') as f:

                    await f.write(await response.read())

                print(f"Downloaded: {filename}")

            else:

                print(f"Failed to download {url}, status code: {response.status}")

    except Exception as e:

        print(f"Error downloading {url}: {e}")


async def download_images_from_website(url, folder="downloaded_images"):

    """Download all images from a website"""

    # Create the download folder if it doesn't exist

    os.makedirs(folder, exist_ok=True)

    

    headers = {

        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'

    }

    

    # Get the webpage content

    response = requests.get(url, headers=headers)

    if response.status_code != 200:

        print(f"Failed to access {url}")

        return

    

    # Parse HTML content

    soup = BeautifulSoup(response.text, 'html.parser')

    

    # Find all image tags

    img_tags = soup.find_all('img')

    img_urls = []

    

    # Extract image URLs

    for img in img_tags:

        img_url = img.get('src')

        if img_url:

            # Convert relative URLs to absolute URLs

            img_url = urljoin(url, img_url)

            img_urls.append(img_url)

    

    print(f"Found {len(img_urls)} images")

    

    # Download images concurrently

    async with aiohttp.ClientSession(headers=headers) as session:

        tasks = [download_image(session, img_url, folder) for img_url in img_urls]

        await asyncio.gather(*tasks)


if __name__ == "__main__":

    website_url = input("Enter the website URL: ")

    output_folder = input("Enter output folder (default: downloaded_images): ") or "downloaded_images"

    

    # Run the async function

    asyncio.run(download_images_from_website(website_url, output_folder))

    print("Download complete!")


This Script Notes:

  1. Uses requests and BeautifulSoup to fetch and parse the webpage
  2. Finds all <img> tags and extracts their URLs
  3. Uses aiohttp and asyncio for concurrent downloads (much faster than sequential)
  4. Creates filenames based on the image URL paths
  5. Adds appropriate file extensions based on Content-Type
  6. Skips already downloaded files

Monday, December 02, 2024

How To Setup Odoo 18 On Ubuntu 24.04 LTS | Easy Step Odoo Setup

 

How To Install Odoo Version 18 On Ubuntu 24.04 LTS Operating System.

In this blog you are going to see how to setup Odoo version 18 on ubuntu 24.04 lts os with easy way.

There are few steps you need to follow nothing else you need.

You need internet connection to download some applications as give in below detail.

1) Download get-pip python file. Click Here.

3) Download any of below editor.

Pycharm

Eclipse

VSCode


Now you have don't need to download anything your self only below packages.


1) Python3.12 or higher version ubuntu already have so you don't need to download.

2) Check python version open terminal and type below command in case not available only this name try to double time press tab key, You will see list of python versions.

=> python

or

=> python3

2.1) You can auto login in python terminal and exit command.

=> exit()

3) Now try to install pip lib in terminal 

=> python get-pip.py install

4) Create new Python virtual environment.

=> python -m -venv yourVEnvName

=> python -m venv odoov18env

6) Try to install below packages.

sudo apt-get install -y python3-dev libxml2-dev libxslt1-dev zlib1g-dev libsasl2-dev libldap2-dev build-essential libssl-dev libffi-dev libmysqlclient-dev libjpeg-dev libpq-dev libjpeg8-dev liblcms2-dev libblas-dev libatlas-base-dev npm postgresql node-less git xfonts-75dpi

7) Try to clone Odoo V18 in your specific path.

=> git clone --single-branch --depth=1 -b 18.0 https://github.com/odoo/odoo

8) Active virtual environment.

=> odoov18env/script/activate

11) Create odoo as super owner. Type below commands in terminal.

11.1) psql -d postgres

11.2) CREATE USER odoo WITH SUPERUSER PASSWORD '1234';

11.3) \q 

12) Install wheel package in your virtual environment

=> python -m pip install wheel

=> python -m pip install wheel --upgrade

13) Go to odoo directory and install packages from requirements.txt

=> python -m pip install -r requitements.txt


14) In case you encounter any error during above step format. Try to find last command which having issue and remove from requirement.txt and execute the step 13 command.

15) Download wkhtml2pdf lib.

15.1) sudo wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb

15.2) sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb

16) Run odoo service as below.

17) python odoo-bin -r odoo -w 1234

18) If you encounter any error try to resolve.

19) Once done try to open browser and execute below code.

=> localhost:8069

20) Try to create new database.


In case you need help please follow below video.


Sunday, September 11, 2022

Setup Odoo V15 in Windows 10 with easy steps

How to install Odoo Version 15 in Windows 10 Operating System.

In this blog you are going to see how to setup Odoo version 15 in windows 10 os with easy way.

There are few steps you need to follow nothing else you need.

You need internet connection to download some applications as give in below detail.

1) First you need to download Python application Click Here.

2) Download get-pip python file. Click Here.

3) Download PostgreSQL Click here.

4) Download any of below editor.

Pycharm

Eclipse

VSCode

5) Install git application Click here.


Now you have don't need to download anything your self only python packages.


1) Now try to install Python.


2) Once you install python open command prompt and type 

=> python


3) You can auto login in python terminal and exit command.

=> exit()


4) Now try to install pip lib in terminal 

=> python get-pip.py install


5) Create new Python virtual environment.

=> python -m -venv yourVEnvName

=> python -m venv odoov15env


6) Try to install git application.


7) Try to clone Odoo V15 in your specific path.

=> git clone --single-branch --depth=1 -b 15.0 https://github.com/odoo/odoo


8) Active virtual environment.

=> odoov15env/Script/activation


9) Install PostgreSQL application.


10) Add password 123 for database as well as pgadmin4.


11) Create odoo as super owner.


12) execute below command.

=> python -m pip install wheel

=> python -m pip install wheel --upgrade


13) Go to odoo directory and install packages from requirements.txt

=> python -m pip install -r requitements.txt


14) In case you encounter any error during above step format. Try to find last command which having issue and remove from requirement.txt and execute the step 12 command.


15) Run odoo service as below.


16) python odoo-bin -r odoo -w 123


17) If you encounter any error try to resolve.


18) Once done try to open browser and execute below code.

=> localhost:8069


19) Try to create new database.


In case you need help please follow below video.


Friday, August 07, 2020

Odoo13 Technical Training | Odoo for beginner | Odoo Free Course

ODOO-13 Technical Training

Are you looking for Odoo13 technical training with example then you are in right place. Below topics covered in this blog.