From bda4452390a9e06a6f8c1e799c8a97087333b90e Mon Sep 17 00:00:00 2001 From: justuser31 Date: Tue, 7 May 2024 22:04:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8,=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=BB=D0=BE=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B8=20=D1=80?= =?UTF-8?q?=D0=B5=D1=86=D0=B5=D0=BF=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reworked/parse.py | 27 ++++++++++++++++++--------- reworked/update_db.py | 8 ++++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/reworked/parse.py b/reworked/parse.py index dcb67b6..32c5db8 100644 --- a/reworked/parse.py +++ b/reworked/parse.py @@ -1,11 +1,14 @@ from requests import get from yaml import load, SafeLoader from reag__ import reag__ +from tqdm import tqdm #### Локализация #### def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta'): - url = f'{prefix}/{el}.ftl' + if '.ftl' not in el: + el += '.ftl' + url = f'{prefix}/{el}' raw = get(url).content.decode('utf-8') locales = {} for i in raw.splitlines(): @@ -18,27 +21,33 @@ def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/s def load_locales(locales_url): locales = {} - for el in locales_url: + for el in tqdm(locales_url): locales = locales | parse_ftl(el) return locales #### Рецепты #### +SafeLoader.add_multi_constructor('', lambda loader, tag_suffix, node: None) + def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'): - url = f'{prefix}/{el}.yml' + if '.yml' not in el: + el += '.yml' + url = f'{prefix}/{el}' yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader) return yml def load_recipes(recipes_url, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'): - for el in recipes_url: + recipes = {} + for el in tqdm(recipes_url): yml = parse_yml(el, prefix) - recipes = {} for element in yml: - product = element["id"] + if 'products' not in element or 'reactants' not in element: + continue + product = element['id'] comps = {} - for elem in element["reactants"]: - comps[elem] = element["reactants"][elem]["amount"] - for id, value in element["products"].items(): + for elem in element['reactants']: + comps[elem] = element['reactants'][elem]['amount'] + for id, value in element['products'].items(): out = value recipes[product] = reag__(comps=comps, out=out, category=el) return recipes diff --git a/reworked/update_db.py b/reworked/update_db.py index 1efac9a..3bdccef 100644 --- a/reworked/update_db.py +++ b/reworked/update_db.py @@ -12,11 +12,15 @@ vols = [30, 50, 100] if inp == '1': print('Парсим и обрабатываем данные...') # Загружаем локализацию - locales_url = ['medicine', 'chemicals'] + locales_url = ['biological', 'botany', 'chemicals', 'cleaning', 'elements', 'fun', + 'gases', 'medicine', 'narcotics', 'physical-desc', 'pyrotechnic', 'toxins', + 'consumable/drink/alcohol', 'consumable/drink/drinks', 'consumable/drink/juice', 'consumable/drink/soda', + 'consumable/food/condiments', 'consumable/food/food', 'consumable/food/ingredients'] locales = load_locales(locales_url) # Загружаем сырые рецепты - recipes_url = ['medicine'] + recipes_url = ['biological', 'botany', 'chemicals', 'cleaning', 'drinks', 'food', + 'fun', 'gas', 'medicine', 'pyrotechnic'] raw_recipes = load_recipes(recipes_url) # Локализируем