This script downloads SVG logos of hotels from Wikimedia Commons and packages them into a zip file.
- Python 3.x
- Required Python packages:
- requests
- beautifulsoup4
- urllib3
-
Open Terminal and navigate to the project directory:
cd path/to/hotel_logo_download
-
Create a virtual environment (required on macOS):
python3 -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
You should see
(venv)
appear at the start of your command prompt. -
Install the required packages:
pip install requests beautifulsoup4 urllib3
- Clone this repository or download the script
- Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Linux # or .\venv\Scripts\activate # On Windows
- Install the required packages:
pip install requests beautifulsoup4 urllib3
-
Make sure your virtual environment is activated (you should see
(venv)
at the start of your command prompt):source venv/bin/activate # On macOS/Linux # or .\venv\Scripts\activate # On Windows
-
Run the script:
python download_svgs.py
The script will:
- Create a
hotel_svgs
directory - Download SVG logos from Wikimedia Commons
- Create a zip file named
hotel_logos_svg.zip
containing all downloaded logos
- The script creates two outputs:
- A
hotel_svgs
directory containing individual SVG files - A
hotel_logos_svg.zip
file containing all downloaded SVGs
- A
- Downloads SVG logos from Wikimedia Commons' hotel logo category
- Handles HTML encoded filenames
- Includes error handling and logging
- Respects Wikimedia's rate limits with random delays between requests
- Creates a convenient zip archive of all downloaded logos
- The script uses a custom User-Agent string to identify itself
- It includes random delays between requests to be respectful to Wikimedia's servers
- All downloaded files are saved in SVG format
- The script includes comprehensive logging to track progress and any issues
The script includes error handling for:
- Network issues
- Missing or invalid SVG links
- File download failures
- File system operations
All errors are logged to the console for debugging purposes.
If you see an "externally-managed-environment" error:
- Make sure you're using a virtual environment
- Never use
sudo
with pip - If you accidentally installed packages globally, you can remove them with:
pip uninstall requests beautifulsoup4 urllib3
- Then follow the installation instructions above using a virtual environment
If you encounter a ModuleNotFoundError
when running the script:
- Make sure you have activated your virtual environment (you should see
(venv)
at the start of your command prompt) - Verify the packages are installed by running:
pip list
- If packages are missing, run the installation command again:
pip install requests beautifulsoup4 urllib3
-
If you get a "command not found" error for
python3
:brew install python
-
If you get permission errors:
- Never use
sudo
with pip - Make sure you're using a virtual environment
- Check that you have write permissions in the project directory
- Never use
-
If you need to start over:
# Deactivate the virtual environment deactivate # Remove the old virtual environment rm -rf venv # Create a new one python3 -m venv venv # Activate it source venv/bin/activate # Install packages pip install requests beautifulsoup4 urllib3