Reviewed-on: #1
Lego Scripts
Collection of various Lego related scripts
Rebrickable Color Data Processing Scripts
rb_colorgrabber.py
- Downloads color data from Rebrickable APIrb2bl_colors.py
- Processes downloaded color data to extract IDs
Prerequisites
- Python 3.7+
- Required Python packages:
requests
- Rebrickable API key (get one from https://rebrickable.com/api/)
- Input file:
colors.csv
from https://rebrickable.com/downloads/
Script Details
rb_colorgrabber.py
Downloads color data from Rebrickable API and saves it as individual JSON files.
Features:
- Fetches color data from Rebrickable API
- Caches results in JSON files
- Implements rate limiting (10-second delay between requests)
- Handles corrupted cache files
- Provides detailed logging
Usage:
- Set your API key in the script
- Ensure
colors.csv
is in the same directory - Run:
python rb_colorgrabber.py
The script will create a colors
directory and save individual JSON files for each color ID.
process_colors.py
Processes the downloaded JSON files to extract BrickLink IDs and create a combined dataset.
Features:
- Reads color data from JSON files
- Extracts BrickLink IDs
- Creates a combined output file
- Handles missing or corrupt data
Usage:
- Ensure you have run
rb_colorgrabber.py
first - Run:
python rb2bl_colors.py
The script will create colors_combined.csv
with the processed data.
File Structure
.
├── colors/ # Directory containing JSON files (created by fetch_colors.py)
│ ├── 1.json
│ ├── 2.json
│ └── ...
├── colors.csv # Input file from Rebrickable
├── fetch_colors.py # Script to fetch data from API
├── process_colors.py # Script to process JSON files
└── colors_combined.txt # Output file (created by process_colors.py)
Error Handling
Both scripts include comprehensive error handling:
- API connection errors
- File read/write errors
- JSON parsing errors
- Missing data handling
Logging
The scripts provide detailed logging information:
- API request status
- File operations
- Error messages
- Processing progress
Best Practices
When using these scripts:
- Don't modify the JSON files manually
- Keep the API key secure
- Respect Rebrickable's rate limits
- Back up your data before processing
Troubleshooting
Common issues and solutions:
-
API Key errors:
- Verify your API key is correct
- Check your API key permissions
-
Missing files:
- Ensure
colors.csv
is present - Run
rb_colorgrabber.py
beforerb2bl_colors.py
- Ensure
-
Rate limiting:
- The scripts include a 10-second delay between requests
- Don't modify this unless you have permission from Rebrickable
License
These scripts are provided as-is under the MIT License.
Description
Languages
Python
100%