RE: LEGO 2 LDraw 2 BL
2019-04-13, 8:05 (This post was last modified: 2019-04-14, 10:36 by David Manley.)
2019-04-13, 8:05 (This post was last modified: 2019-04-14, 10:36 by David Manley.)
(2019-04-12, 12:34)David Manley Wrote: It is do-able. I've just knocked something together to process the rebrickable data using their published API. My attempt at producing a reasonable output is visible here.
There are a couple of rough edges to remove from my solution but I'll post my approach and scripts on here in the morning, should there be any interest.
David
If anyone wants to tutu with this, this zip file contains the necessary scripts. The requirements are;
- Windows PowerShell
- curl (free to download from https://curl.haxx.se/)
- saxon (free to download the Home edition from http://www.saxonica.com)
- you have a rebrickable account and already have an API key or you obtain a free API key for your account from rebrickable
- I have been running this on Windows 10, using PowerShell 5. It should run on earlier versions of Windows, depending on which version of PowerShell is installed on the OS. Try it and see.
- I'd suggest you alter the PowerShell script part_mapping_generate.ps1 on line 48 and update it with the path to your installation of saxon. You can pass this value in as a command line parameter if you so wish but I suggest this will quickly become tiresome
- While the output format appears to be okay, I need to do some checks on whether all the parts have been output. According to Rebrickable's website, they have 32 000+ parts in their database. The generated XML file currently contains 5 000+ parts. I'll to a bit of digging into this.
- Some rebrickable part ids map to multiple part ids in other systems. For example this part lists two LDraw part numbers. This can occur for systems other than just LDraw. My unconfirmed suspicion is that the first part number listed when there are multiple matches should be taken as the "best" match.
- I don't know whether rebrickable differentiates between the part id being the same between two systems (e.g. rebrickable and LDraw) and a part being only in rebrickable but not in LDraw. When the part id is the same, I think it does not explicitly identify the LDraw part id but is it doing the same thing when there is no equivalent LDraw part? Something I shall be digging in to.
- I keep forgetting how much I dislike PowerShell scripting.
- The command is invoked from the Powershell command line thusly;
.\part_mapping_generate.ps1 your-api-key xml-output-file-name json-output-file-name
- The parameter values influence its behaviour
- .\part_mapping_generate.ps1 your-api-key
Queries rebrickable and output XML to standard output
- .\part_mapping_generate.ps1 your-api-key abc.xml
Queries rebrickable and output XML to the file abc.xml
- .\part_mapping_generate.ps1 your-api-key abc.xml abc.jsn
Queries rebrickable, output XML to the file abc.xml and JSON interim output to abc.jsn
- .\part_mapping_generate.ps1 "" abc.xml abc.jsn
Takes its JSON input from abc.jsn rather than querying rebrickable and output XML to the file abc.xml
- .\part_mapping_generate.ps1 "" "" abc.jsn
Takes its JSON input from abc.jsn rather than querying rebrickable and output XML to standard output
Regards,
David