Добавление функции load_recipe() в parse.py

Добавление функции get_all() для класса reag__
main
wadehusky 7 months ago
parent 9f09fd67f4
commit e5c7c65816

@ -1,5 +1,6 @@
from requests import get from requests import get
from yaml import load, SafeLoader from yaml import load, SafeLoader
from reag__ import reag__
def parse_yml(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/Resources/Prototypes/Recipes/Reactions/medicine.yml'): 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) yml = load(get(url).content.decode('utf-8'), Loader=SafeLoader)
@ -15,3 +16,16 @@ def parse_ftl(url = 'https://raw.githubusercontent.com/SerbiaStrong-220/space-st
locale = splitted[2] locale = splitted[2]
locales[name] = locale locales[name] = locale
return locales return locales
def load_recipe(yml = parse_yml()):
recipes = {}
for element in yml:
category = "medicine"
product = element["id"]
comps = {}
for elem in element["reactants"]:
comps[elem] = element["reactants"][elem]["amount"]
for id, value in element["products"].items():
out = value
recipes[product] = reag__(category=category, comps=comps, out=out)
return recipes

@ -1,8 +1,10 @@
class reag__: class reag__:
def __init__(category = '-', comps, out): def __init__(self, category: str = '-', comps = {}, out: int = 0):
# medicine # medicine
self.category = category self.category = category
# {'инапровалин': 1, 'углерод': 1} # {'инапровалин': 1, 'углерод': 1}
self.comps = comps self.comps = comps
# 2 # 2
self.out = out self.out = out
def get_all(self):
return [self.category, self.comps, self.out]

Loading…
Cancel
Save