import datetime import json import os import shutil import sys YANDEX_SEARCH_ENGINE_SECTION = json.loads(''' { "base": { "aliases": [ "yandex" ], "classification": "general", "name": "Yandex", "partnerCode": "", "urls": { "search": { "base": "https://yandex.ru/search/", "params": [ { "name": "clid", "value": "{partnerCode}" } ], "searchTermParamName": "text" }, "suggestions": { "base": "https://suggest.yandex.ru/suggest-ff.cgi", "params": [ { "name": "clid", "value": "{partnerCode}" } ], "searchTermParamName": "part" } } }, "id": "", "identifier": "yandex", "last_modified": 0, "recordType": "engine", "schema": 0, "variants": [ { "environment": { "allRegionsAndLocales": true } } ] } ''') YANDEX_ICON_SECTION = json.loads(''' { "schema": 0, "imageSize": 32, "attachment": { "hash": "6bb91f1d74389b18bce6e71772e4c5573648c1a4823338193f700afdf8216be5", "size": 5750, "filename": "yandex-32-firefox.png", "location": "main-workspace/search-config-icons/1f0aef96-9d62-4519-906d-379b710a80e8.ico", "mimetype": "image/x-icon" }, "engineIdentifiers": [ "yandex" ], "filter_expression": "env.appinfo.ID == \\"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}\\"", "id": "", "last_modified": 0 } ''') YANDEX_SEARCH_ENGINE_ID = "403a24ac-3e95-4581-88e4-a479eb4ce558" YANDEX_ICON_ID = "32dc5c21-98c7-4355-8603-398c9f5eec49" # ROSA Linux PARTNER_CLID = "2800424" SEARCH_CONFIG_RELATIVE_PATH = "services/settings/dumps/main/search-config-v2.json" SEARCH_CONFIG_ICONS_RELATIVE_PATH = "services/settings/dumps/main/search-config-icons.json" YANDEX_ICON_META_RELATIVE_DIR = "services/settings/dumps/main/search-config-icons/" search_config_path = SEARCH_CONFIG_RELATIVE_PATH if not os.path.isfile(search_config_path): print(search_config_path, "not found") exit(1) search_config_icons_path = SEARCH_CONFIG_ICONS_RELATIVE_PATH if not os.path.isfile(search_config_icons_path): print(search_config_icons_path, "not found") exit(2) yandex_icon_meta_path = os.path.join(YANDEX_ICON_META_RELATIVE_DIR, YANDEX_ICON_ID + ".meta.json") YANDEX_SEARCH_ENGINE_SECTION["id"] = YANDEX_SEARCH_ENGINE_ID YANDEX_SEARCH_ENGINE_SECTION["base"]["partnerCode"] = PARTNER_CLID timestamp = int( datetime.datetime.now().timestamp() ) * 1000 YANDEX_SEARCH_ENGINE_SECTION["last_modified"] = timestamp YANDEX_SEARCH_ENGINE_SECTION["schema"] = timestamp YANDEX_ICON_SECTION["id"] = YANDEX_ICON_ID YANDEX_ICON_SECTION["last_modified"] = timestamp YANDEX_ICON_SECTION["schema"] = timestamp search_config = None with open(search_config_path) as f: search_config = json.load(f) f.close() yandex_search_engine_inserted = False for i, engine in enumerate(search_config["data"]): if "globalDefault" in engine: engine["globalDefault"] = "yandex" engine["last_modified"] = timestamp engine["schema"] = timestamp elif "orders" in engine: for order in engine["orders"]: if "order" in order: yandex_inserted = False for s in order["order"]: if s == "yandex": yandex_inserted = True if not yandex_inserted: order["order"] = ["yandex"] + order["order"] engine["last_modified"] = timestamp engine["schema"] = timestamp elif "id" in engine and engine["id"] == YANDEX_SEARCH_ENGINE_ID: yandex_search_engine_inserted = True search_config["data"][i] = YANDEX_SEARCH_ENGINE_SECTION search_config["timestamp"] = timestamp if not yandex_search_engine_inserted: search_config["data"] = [YANDEX_SEARCH_ENGINE_SECTION] + search_config["data"] with open(search_config_path, 'w', encoding='utf8') as f: json.dump(search_config, f, ensure_ascii=False, indent=2) f.close() search_config_icons = None with open(search_config_icons_path) as f: search_config_icons = json.load(f) f.close() yandex_icon_inserted = False for i, icon in enumerate(search_config_icons["data"]): if "id" in icon and icon["id"] == YANDEX_ICON_ID: yandex_icon_inserted = True search_config_icons["data"][i] = YANDEX_ICON_SECTION search_config_icons["timestamp"] = timestamp if not yandex_icon_inserted: search_config_icons["data"] = [YANDEX_ICON_SECTION] + search_config_icons["data"] with open(search_config_icons_path, 'w', encoding='utf8') as f: json.dump(search_config_icons, f, ensure_ascii=False, indent=2) f.close() with open(yandex_icon_meta_path, 'w', encoding='utf8') as f: json.dump(YANDEX_ICON_SECTION, f, ensure_ascii=False) f.close() YANDEX_ICON_RELATIVE_DIR = "services/settings/dumps/main/search-config-icons/" src_icon_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), YANDEX_ICON_ID) dst_icon_path = os.path.join(YANDEX_ICON_RELATIVE_DIR, YANDEX_ICON_ID) shutil.copy(src_icon_path, dst_icon_path) exit(0)