Мелкие правки, добавление источников локализации и рецептов

main
justuser31 7 months ago
parent 53d540c841
commit bda4452390

@ -1,11 +1,14 @@
from requests import get from requests import get
from yaml import load, SafeLoader from yaml import load, SafeLoader
from reag__ import reag__ 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'): 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') raw = get(url).content.decode('utf-8')
locales = {} locales = {}
for i in raw.splitlines(): 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): def load_locales(locales_url):
locales = {} locales = {}
for el in locales_url: for el in tqdm(locales_url):
locales = locales | parse_ftl(el) locales = locales | parse_ftl(el)
return locales 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'): 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) yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
return yml return yml
def load_recipes(recipes_url, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'): 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) yml = parse_yml(el, prefix)
recipes = {}
for element in yml: for element in yml:
product = element["id"] if 'products' not in element or 'reactants' not in element:
continue
product = element['id']
comps = {} comps = {}
for elem in element["reactants"]: for elem in element['reactants']:
comps[elem] = element["reactants"][elem]["amount"] comps[elem] = element['reactants'][elem]['amount']
for id, value in element["products"].items(): for id, value in element['products'].items():
out = value out = value
recipes[product] = reag__(comps=comps, out=out, category=el) recipes[product] = reag__(comps=comps, out=out, category=el)
return recipes return recipes

@ -12,11 +12,15 @@ vols = [30, 50, 100]
if inp == '1': if inp == '1':
print('Парсим и обрабатываем данные...') 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) 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) raw_recipes = load_recipes(recipes_url)
# Локализируем # Локализируем

Loading…
Cancel
Save