import json import sys import datetime YANDEX_SECTION = json.loads(''' { "appliesTo": [ { "default": "yes", "included": { "everywhere": true } } ], "id": "a0e7f96a-14e0-4d56-9f54-e0c7e49fd306", "last_modified": 1679065511545, "schema": 1639069022290, "webExtension": { "id": "yandex@search.mozilla.org" } } ''') search_config = None with open(sys.argv[1]) as f: search_config = json.load(f) inserted = False for engine in search_config["data"]: if engine["webExtension"]["id"] == "yandex@search.mozilla.org": inserted = True engine = YANDEX_SECTION else: for applies in engine["appliesTo"]: if "default" in applies and applies["default"] == "yes": applies["default"] = "no" if not inserted: search_config["data"] = [YANDEX_SECTION] + search_config["data"] search_config["timestamp"] = int( datetime.datetime.now().timestamp() ) * 1000 with open(sys.argv[1], 'w') as f: json.dump(search_config, f, indent=2)