Загрузка списком локализаций и рецептов

main
justuser31 7 months ago
parent 0a98ef930b
commit 5cce77aa10

@ -2,11 +2,10 @@ from requests import get
from yaml import load, SafeLoader from yaml import load, SafeLoader
from reag__ import reag__ from reag__ import reag__
def parse_yml(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions/medicine.yml'): #### Локализация ####
yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
return yml
def parse_ftl(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Locale/ru-RU/reagents/meta/medicine.ftl'): 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'
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():
@ -17,8 +16,22 @@ def parse_ftl(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-st
locales[name] = locale locales[name] = locale
return locales return locales
def load_recipes(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions/medicine.yml', category = '-'): def load_locales(locales_url):
yml = parse_yml(url) locales = {}
for el in locales_url:
locales = locales | parse_ftl(el)
return locales
#### Рецепты ####
def parse_yml(el, prefix = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions'):
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'):
for el in recipes_url:
yml = parse_yml(el, prefix)
recipes = {} recipes = {}
for element in yml: for element in yml:
product = element["id"] product = element["id"]
@ -27,10 +40,12 @@ def load_recipes(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space
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__(category=category, comps=comps, out=out) recipes[product] = reag__(category=el, comps=comps, out=out)
return recipes return recipes
#### Локализируем ####
def localize(recipes, locale): def localize(recipes, locale):
loc_recipes = {} loc_recipes = {}
# Итерируем элементы # Итерируем элементы

Loading…
Cancel
Save