Compare commits

..

No commits in common. "bda4452390a9e06a6f8c1e799c8a97087333b90e" and "320a7204e30ae8adef04cc51696a92da60e852e5" have entirely different histories.

3 changed files with 12 additions and 34 deletions

View File

@ -1,5 +1,4 @@
from precalc__ import precalc__
from db import load
global expanded
def expand_recipe(recipe, recipes, main = False):
@ -51,17 +50,9 @@ def calc(element, amount, recipes):
return expanded, vol_in, vol_out
def calc_all(recipes, amount):
precalc = {}
for el in recipes:
precalc[el] = precalc__(calc(el, amount, recipes))
return precalc
def precalc(element, amount):
try:
# Загружаем рецепты с нужным количеством
recipes = load(f'{amount}_calc.json', 'precalc')
except:
return 'Нету такого файла или вещества'
return recipes[element]

View File

@ -1,14 +1,11 @@
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'):
if '.ftl' not in el:
el += '.ftl'
url = f'{prefix}/{el}'
url = f'{prefix}/{el}.ftl'
raw = get(url).content.decode('utf-8')
locales = {}
for i in raw.splitlines():
@ -21,33 +18,27 @@ def parse_ftl(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/s
def load_locales(locales_url):
locales = {}
for el in tqdm(locales_url):
for el in 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'):
if '.yml' not in el:
el += '.yml'
url = f'{prefix}/{el}'
url = f'{prefix}/{el}.yml'
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'):
recipes = {}
for el in tqdm(recipes_url):
for el in recipes_url:
yml = parse_yml(el, prefix)
recipes = {}
for element in yml:
if 'products' not in element or 'reactants' not in element:
continue
product = element['id']
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

View File

@ -12,15 +12,11 @@ vols = [30, 50, 100]
if inp == '1':
print('Парсим и обрабатываем данные...')
# Загружаем локализацию
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_url = ['medicine', 'chemicals']
locales = load_locales(locales_url)
# Загружаем сырые рецепты
recipes_url = ['biological', 'botany', 'chemicals', 'cleaning', 'drinks', 'food',
'fun', 'gas', 'medicine', 'pyrotechnic']
recipes_url = ['medicine']
raw_recipes = load_recipes(recipes_url)
# Локализируем