2025-01-28 16:59:55 +01:00
2025-01-28 16:59:01 +01:00
2025-01-28 15:41:27 +01:00
2025-01-28 16:59:01 +01:00

Lego Scripts

Collection of various Lego related scripts

Rebrickable Color Data Processing Scripts

  1. rb_colorgrabber.py - Downloads color data from Rebrickable API
  2. rb2bl_colors.py - Processes downloaded color data to extract IDs

Prerequisites

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:
  1. Set your API key in the script
  2. Ensure colors.csv is in the same directory
  3. 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:
  1. Ensure you have run rb_colorgrabber.py first
  2. 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:

  1. Don't modify the JSON files manually
  2. Keep the API key secure
  3. Respect Rebrickable's rate limits
  4. Back up your data before processing

Troubleshooting

Common issues and solutions:

  1. API Key errors:

    • Verify your API key is correct
    • Check your API key permissions
  2. Missing files:

    • Ensure colors.csv is present
    • Run rb_colorgrabber.py before rb2bl_colors.py
  3. 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
Collection of various Lego related scripts
Readme 34 KiB
Languages
Python 100%