Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save click0/46b0ff88361956e430bfcf1e88b5c351 to your computer and use it in GitHub Desktop.
Save click0/46b0ff88361956e430bfcf1e88b5c351 to your computer and use it in GitHub Desktop.

Revisions

  1. @Bilka2 Bilka2 created this gist Sep 16, 2020.
    15 changes: 15 additions & 0 deletions factorio_blueprint_string_edit.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import json
    import zlib
    import base64

    original_bp_string = '0eNp9j80OgjAQhN9lzq0RFNC+ijGGnw1uQhdCi5GQvrstXjx5m9mfb2c3NMNC08ziYTZwO4qDuW1w3Es9pJpfJ4IBe7JQkNomVztHthlYem3r9slCOkdQYOnoDZOFuwKJZ8/05e1mfchiG5rjwH+SwjS6uDxKShCB+nQoFNYoskOR7sQ0LvWmeeyW1vMr0rWNeiB9gslDSrBnNj8vKrxodjs2v2Tn6nytyio7lkUZwgd0Blhx'
    bp_json = json.loads(zlib.decompress(base64.b64decode(original_bp_string[1:])).decode('utf8'))

    # there is one entity in the blueprint, it's an assembler with a item request for 2 prod-3 modules and no recipe set
    # for the fields of the blueprint json see https://wiki.factorio.com/Blueprint_string_format
    bp_json['blueprint']['entities'][0]['items'] = {'copper-plate': 200} # overwrites existing item request
    bp_json['blueprint']['entities'][0]['recipe'] = 'copper-cable' # creates new key/value pair


    changed_bp_string = '0' + base64.b64encode(zlib.compress(bytes(json.dumps(bp_json), 'utf8'))).decode('utf8')
    print(changed_bp_string)