|
|
@ -2,33 +2,37 @@ import yaml
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
from fluent.syntax import parse, ast
|
|
|
|
from fluent.syntax import parse, ast
|
|
|
|
from db import write_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yaml.SafeLoader.add_multi_constructor("", lambda loader, tag_suffix, node: None)
|
|
|
|
yaml.SafeLoader.add_multi_constructor("", lambda loader, tag_suffix, node: None)
|
|
|
|
|
|
|
|
|
|
|
|
# список реагентов
|
|
|
|
# медицинские реагентов
|
|
|
|
REAGENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/medicine.yml"
|
|
|
|
REAGENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/medicine.yml"
|
|
|
|
|
|
|
|
|
|
|
|
# список токсинов
|
|
|
|
|
|
|
|
TOXINS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/toxins.yml"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# рецепты медицинских реагентов
|
|
|
|
|
|
|
|
RECIPES_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Recipes/Reactions/medicine.yml"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# локализация медицинских реагентов
|
|
|
|
|
|
|
|
MEDICINE_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/medicine.ftl"
|
|
|
|
MEDICINE_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/medicine.ftl"
|
|
|
|
|
|
|
|
RECIPES_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Recipes/Reactions/medicine.yml"
|
|
|
|
|
|
|
|
|
|
|
|
# локализация элементов из раздатчика химикатов
|
|
|
|
# элементы раздатчика химикатов
|
|
|
|
|
|
|
|
ELEMENTS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/elements.yml"
|
|
|
|
ELEMENTS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/elements.ftl"
|
|
|
|
ELEMENTS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/elements.ftl"
|
|
|
|
|
|
|
|
|
|
|
|
# локализация токсинов/"токсичных реагентов" типа пакса и т.п
|
|
|
|
# токсины
|
|
|
|
|
|
|
|
TOXINS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/toxins.yml"
|
|
|
|
TOXINS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/toxins.ftl"
|
|
|
|
TOXINS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/toxins.ftl"
|
|
|
|
|
|
|
|
|
|
|
|
# локализация наркотиков/наркотических препаратов
|
|
|
|
# локализация наркотиков/наркотических препаратов
|
|
|
|
NARCOTICS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/narcotics.ftl"
|
|
|
|
NARCOTICS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/narcotics.ftl"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# газы
|
|
|
|
|
|
|
|
GASES_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/gases.yml"
|
|
|
|
|
|
|
|
GASES_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/gases.ftl"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# все съедобное и питьевое
|
|
|
|
|
|
|
|
FOOD_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/dev/Resources/Prototypes/Reagents/Consumable/Food/food.yml"
|
|
|
|
|
|
|
|
DRINKS_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Prototypes/Reagents/Consumable/Drink/drinks.yml"
|
|
|
|
|
|
|
|
DRINKS_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/drink/drinks.ftl"
|
|
|
|
|
|
|
|
FOOD_LOCALISATION_URL = "https://github.com/SerbiaStrong-220/space-station-14/raw/master/Resources/Locale/ru-RU/reagents/meta/consumable/food/ingredients.ftl"
|
|
|
|
|
|
|
|
|
|
|
|
localisation_list = [MEDICINE_LOCALISATION_URL, ELEMENTS_LOCALISATION_URL, TOXINS_LOCALISATION_URL,
|
|
|
|
localisation_list = [MEDICINE_LOCALISATION_URL, ELEMENTS_LOCALISATION_URL, TOXINS_LOCALISATION_URL,
|
|
|
|
NARCOTICS_LOCALISATION_URL]
|
|
|
|
GASES_LOCALISATION_URL, DRINKS_LOCALISATION_URL, FOOD_LOCALISATION_URL, NARCOTICS_LOCALISATION_URL]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Reagent:
|
|
|
|
class Reagent:
|
|
|
@ -37,13 +41,13 @@ class Reagent:
|
|
|
|
self.__desc: str = init_data.get("desc")
|
|
|
|
self.__desc: str = init_data.get("desc")
|
|
|
|
self.__recipe: dict = init_data.get("reactants")
|
|
|
|
self.__recipe: dict = init_data.get("reactants")
|
|
|
|
self.__product = init_data.get("products")
|
|
|
|
self.__product = init_data.get("products")
|
|
|
|
# raw значения которые не нужны
|
|
|
|
# raw значения которые обработаны
|
|
|
|
|
|
|
|
|
|
|
|
self.heat: bool = init_data.get("heat")
|
|
|
|
self.heat: bool = init_data.get("heat")
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
def name(self):
|
|
|
|
return localise(self.__name)
|
|
|
|
return localise(self.__name).capitalize()
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def description(self):
|
|
|
|
def description(self):
|
|
|
@ -51,36 +55,60 @@ class Reagent:
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def recipe(self):
|
|
|
|
def recipe(self):
|
|
|
|
#result = [self.heat]
|
|
|
|
|
|
|
|
result = []
|
|
|
|
result = []
|
|
|
|
for item in self.__recipe:
|
|
|
|
for item in self.__recipe:
|
|
|
|
# Приводим к НОРМАЛЬНОМУ виду
|
|
|
|
# Приводим к НОРМАЛЬНОМУ виду
|
|
|
|
# "Бикаридин": [ [0, "Углерод", 1], [1, "Инапровалин"] ]
|
|
|
|
# "Бикаридин": [ [0, "Углерод", 1], [1, "Инапровалин"] ]
|
|
|
|
|
|
|
|
result.append([self.__recipe[item]["reagent"], localise(item).capitalize(), self.__recipe[item]["amount"]])
|
|
|
|
#result.append([item, self.__recipe[item]["amount"], self.__recipe[item]["reagent"]])
|
|
|
|
|
|
|
|
result.append([ self.__recipe[item]["reagent"], item, self.__recipe[item]["amount"] ])
|
|
|
|
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def dict(self):
|
|
|
|
|
|
|
|
# Нам нужен только рецепт
|
|
|
|
|
|
|
|
# return {"name": self.name, "desc": self.description, "recipe": self.recipe}
|
|
|
|
|
|
|
|
return self.recipe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_localisation():
|
|
|
|
def load_localisation():
|
|
|
|
data = {}
|
|
|
|
data = {"elements": {}, "reagents": {}, "gases": {}, "food": {}, "drinks": {}, "total": {}}
|
|
|
|
|
|
|
|
elements = yaml.load(requests.get(ELEMENTS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
|
|
|
|
|
|
|
|
for element in elements:
|
|
|
|
|
|
|
|
data["elements"][element["id"]] = {"name": element["name"], "desc": element["desc"]}
|
|
|
|
|
|
|
|
reagents = yaml.load(requests.get(REAGENTS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
|
|
|
|
|
|
|
|
for reagent in reagents:
|
|
|
|
|
|
|
|
data["reagents"][reagent["id"]] = {"name": reagent["name"], "desc": reagent["desc"]}
|
|
|
|
|
|
|
|
gases = yaml.load(requests.get(GASES_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
|
|
|
|
|
|
|
|
for gase in gases:
|
|
|
|
|
|
|
|
data["gases"][gase["id"]] = {"name": gase["name"], "desc": gase["desc"]}
|
|
|
|
|
|
|
|
food = yaml.load(requests.get(FOOD_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
|
|
|
|
|
|
|
|
for item in food:
|
|
|
|
|
|
|
|
data["food"][item["id"]] = {"name": item["name"], "desc": item["desc"]}
|
|
|
|
|
|
|
|
drinks = yaml.load(requests.get(DRINKS_URL).content.decode("utf-8"), Loader=yaml.SafeLoader)
|
|
|
|
|
|
|
|
for drink in drinks:
|
|
|
|
|
|
|
|
data["drinks"][drink["id"]] = {"name": drink["name"], "desc": drink["desc"]}
|
|
|
|
|
|
|
|
|
|
|
|
for url in localisation_list:
|
|
|
|
for url in localisation_list:
|
|
|
|
content = requests.get(url).content.decode("utf-8")
|
|
|
|
content = requests.get(url).content.decode("utf-8")
|
|
|
|
for entry in parse(content).body:
|
|
|
|
for entry in parse(content).body:
|
|
|
|
if isinstance(entry, ast.Message):
|
|
|
|
if isinstance(entry, ast.Message):
|
|
|
|
data[entry.id.name] = entry.value.elements[0].value
|
|
|
|
data["total"][entry.id.name] = entry.value.elements[0].value
|
|
|
|
|
|
|
|
|
|
|
|
with open("locale.json", mode="w", encoding="utf-8") as localisation_file:
|
|
|
|
with open("locale.json", mode="w", encoding="utf-8") as localisation_file:
|
|
|
|
json.dump(data, localisation_file, ensure_ascii=False, indent=2)
|
|
|
|
json.dump(data, localisation_file, ensure_ascii=False, indent=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def localise(key: str) -> str:
|
|
|
|
def localise(key: str) -> str:
|
|
|
|
|
|
|
|
# TODO: почистить это говно
|
|
|
|
with open("locale.json", mode="r", encoding="utf-8") as file:
|
|
|
|
with open("locale.json", mode="r", encoding="utf-8") as file:
|
|
|
|
data = json.load(file)
|
|
|
|
data = json.load(file)
|
|
|
|
return data.get(key, f"[!] {key}")
|
|
|
|
if key in data["elements"]:
|
|
|
|
|
|
|
|
return data["total"].get(data["elements"][key]["name"])
|
|
|
|
|
|
|
|
elif key in data["reagents"]:
|
|
|
|
|
|
|
|
return data["total"].get(data["reagents"][key]["name"])
|
|
|
|
|
|
|
|
elif key in data["gases"]:
|
|
|
|
|
|
|
|
return data["total"].get(data["gases"][key]["name"])
|
|
|
|
|
|
|
|
elif key in data["food"]:
|
|
|
|
|
|
|
|
return data["total"].get(data["food"][key]["name"])
|
|
|
|
|
|
|
|
elif key in data["drinks"]:
|
|
|
|
|
|
|
|
return data["total"].get(data["drinks"][key]["name"])
|
|
|
|
|
|
|
|
elif key in data["total"]:
|
|
|
|
|
|
|
|
return data["total"][key]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return f"[!] {key}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
load_localisation()
|
|
|
|
load_localisation()
|
|
|
@ -101,7 +129,9 @@ for item in yaml.load(requests.get(RECIPES_URL).content.decode("utf-8"), Loader=
|
|
|
|
content[item["id"]]["products"] = item["products"]
|
|
|
|
content[item["id"]]["products"] = item["products"]
|
|
|
|
|
|
|
|
|
|
|
|
reagents = [Reagent(init_data=content[item]) for item in content if "reactants" in content[item]]
|
|
|
|
reagents = [Reagent(init_data=content[item]) for item in content if "reactants" in content[item]]
|
|
|
|
|
|
|
|
print(reagents[0].name)
|
|
|
|
|
|
|
|
print(reagents[0].recipe)
|
|
|
|
|
|
|
|
|
|
|
|
db = {x.name: x.dict() for x in reagents}
|
|
|
|
db = {x.name: x.recipe for x in reagents}
|
|
|
|
with open("db.json", mode="w", encoding="utf-8") as db_file:
|
|
|
|
with open("db.json", mode="w", encoding="utf-8") as db_file:
|
|
|
|
json.dump(db, db_file, ensure_ascii=False, indent=2)
|
|
|
|
json.dump(db, db_file, ensure_ascii=False, indent=2)
|
|
|
|