def datetime_nanban2str_out(dt_nanban): filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) has_dt_nanban = (dt_nanban is not None) if not has_dt_nanban: data = { "server": Server.server_lang2name(server, lang), "has_dt_nanban": has_dt_nanban, } str_out = HenriqueJinja2.textfile2text(filepath, data) return str_out td_nanban = dt_nanban - utc_now tzdb = HenriqueLocale.lang2tzdb(lang) str_timedelta_nanban = NanbanTimedelta.timedelta_lang2text( td_nanban, lang) logger.debug({ "server_codename": server_codename, "server": server, "dt_nanban": dt_nanban, }) data = { "server": Server.server_lang2name(server, lang), "dt_nanban": NanbanTimedelta.datetime2text(dt_nanban, tzdb), "dt_now": NanbanTimedelta.datetime2text(utc_now, tzdb), "timedelta_nanban": str_timedelta_nanban, "has_dt_nanban": has_dt_nanban, } str_out = HenriqueJinja2.textfile2text(filepath, data) return str_out
def tradegood_lang2title(cls, tradegood, lang): filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = { "tradegood_name": Tradegood.tradegood_lang2name(tradegood, lang), } title = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return title
def codename_lang2text(cls, port_codename, lang): port = Port.codename2port(port_codename) products = Port.port2products(port) # ports = Tradegood.port2tradegoods(port_codename) # tradegood = Tradegood.codename2tradegood(tg_codename) # assert_is_not_none(tradegood_doc, tg_codename) filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) def product2data(product): tg_codename = Product.product2tradegood(product) tg = Tradegood.codename2tradegood(tg_codename) h = { "name": Tradegood.tradegood_lang2name(tg, lang), } return h data = { "port_name": Port.port_lang2name(port, lang), "product_data_list": lmap(product2data, products), } text_out = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return text_out
def port_lang2title(cls, port, lang): filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = { "port_name": Port.port_lang2name(port, lang), } title = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return title
def entity2response_block(cls, entity, packet, ): logger = HenriqueLogger.func_level2logger(cls.packet2response, logging.DEBUG) chatroom = Chatroom.codename2chatroom(KhalaPacket.packet2chatroom(packet)) if Chatroom.chatroom2codename(chatroom) != ChatroomKakaotalk.codename(): return locale = Chatroom.chatroom2locale(chatroom) lang = LocaleTool.locale2lang(locale) v = FoxylibEntity.entity2value(entity) codename = ChatroomuserEntity.value_packet2codename(v, packet) logger.debug({"codename": codename, "entity": entity, "v": v, }) chatroomuser = Chatroomuser.codename2chatroomuser(codename) comments = Chatroomuser.chatroomuser2comments(chatroomuser) comment = choice(comments) if comments else None filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = {"name": codename, "comment": comment, "str_aliases": ", ".join(Chatroomuser.chatroomuser2aliases(chatroomuser)), } text_out = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return text_out
def codename_lang2text(cls, culture_codename, lang): culture = Culture.codename2culture(culture_codename) filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = {"name": Culture.culture_lang2name(culture, lang)} text_out = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return text_out
def _json_yaml(cls, ): filepath = os.path.join(REPO_DIR, "henrique", "env", "yaml", "env.henrique.part.yaml") if not os.path.exists(filepath): return None data = { "HOME_DIR": str(Path.home()), "REPO_DIR": REPO_DIR, "ENV_DIR": os.path.join(REPO_DIR, "henrique", "env"), } utf8 = HenriqueJinja2.textfile2text(filepath, data) json_yaml = yaml.load(utf8, Loader=BaseLoader) return json_yaml
def codename_lang2text(cls, port_codename, lang): port = Port.codename2port(port_codename) culture = Culture.codename2culture(Port.port2culture(port)) filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = { "culture_name": Culture.culture_lang2name(culture, lang), "port_name": Port.port_lang2name(port, lang) } text_out = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return text_out
def codename_lang2text(cls, port_codename, lang): logger = HenriqueLogger.func_level2logger(cls.codename_lang2text, logging.DEBUG) port = Port.codename2port(port_codename) culture = Culture.codename2culture(Port.port2culture(port)) tgt_codenames = luniq( filter( bool, map(Product.product2tradegoodtype, Product.port2products(port_codename)))) tradegoodtype_list = sorted(map(Tradegoodtype.codename2tradegoodtype, tgt_codenames), key=Tradegoodtype.key) def tgt_list2text_resistant(tgt_list): logger.debug({"tgt_list": tgt_list}) if not tgt_list: return None return ", ".join([ Tradegoodtype.tradegoodtype_lang2name(tgt, lang) for tgt in tgt_list ]) tradegoodtypes_resistant = tgt_list2text_resistant(tradegoodtype_list) comments = Port.port_lang2comments(port, lang) comment = choice(comments) if comments else None filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = { "name": Port.port_lang2name(port, lang), "culture": Culture.culture_lang2name(culture, lang), "tradegoodtypes_resistant": tradegoodtypes_resistant, "comment": comment, } text_out = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return text_out
def codename_lang2text(cls, tradegood_codename, lang): tradegood = Tradegood.codename2tradegood(tradegood_codename) prefer_list = Prefer.tradegood2prefers(tradegood_codename) def prefer2culture_name(prefer): culture = Culture.codename2culture(Prefer.prefer2culture(prefer)) culture_name = Culture.culture_lang2name(culture, lang) return culture_name preferred_culture_list = lmap(prefer2culture_name, prefer_list) preferred_cultures = ", ".join(preferred_culture_list) filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = { "tradegood_name": Tradegood.tradegood_lang2name(tradegood, lang), "preferred_cultures": preferred_cultures, } text_out = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return text_out
def codename_lang2text(cls, culture_codename, lang): filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) data = cls.codename_lang2json(culture_codename, lang) text_out = HenriqueJinja2.textfile2text(filepath, data) return Rowsblock.text2norm(text_out)
def codename_lang2text(cls, tradegood_codename, lang): logger = HenriqueLogger.func_level2logger(cls.codename_lang2text, logging.DEBUG) tradegood = Tradegood.codename2tradegood(tradegood_codename) filepath = os.path.join(FILE_DIR, "tmplt.{}.part.txt".format(lang)) tgt_codename = Tradegood.tradegood2tradegoodtype(tradegood) tgt = Tradegoodtype.codename2tradegoodtype( tgt_codename) if tgt_codename else None category = Tradegoodtype.tradegoodtype2category(tgt) if tgt else None ports_selling = Port.tradegood2ports(tradegood_codename) prefers = Prefer.tradegood2prefers(tradegood_codename) # def prefers2cultures(prefers): # culture_codenames = luniq(map(Prefer.prefer2culture, prefers)) # return lmap(Culture.codename2culture, culture_codenames) culture_codenames_preferred = luniq(map(Prefer.prefer2culture, prefers)) if prefers else [] # culture_list_preferred = prefers2cultures(prefers) if prefers else [] port_list_preferred = lchain( *map(Port.culture2ports, culture_codenames_preferred)) def port2is_resistant(port): if not tgt: return False products = Product.port2products(Port.port2codename(port)) tgt_codenames_port = smap(Product.product2tradegoodtype, products) logger.debug({ "tgt": tgt, "tgt_codenames_port": tgt_codenames_port }) return Tradegoodtype.tradegoodtype2codename( tgt) in tgt_codenames_port port_list_preferred_resistant = lfilter(port2is_resistant, port_list_preferred) def ports2str(ports): if not ports: return None return ", ".join( [Port.port_lang2name(port, lang) for port in ports]) def culture_codenames2str(culture_codenames): if not culture_codenames: return None logger.debug({"culture_codenames": culture_codenames}) cultures = lmap(Culture.codename2culture, culture_codenames) return ", ".join([ Culture.culture_lang2name(culture, lang) for culture in cultures ]) logger.debug( {"culture_codenames_preferred": culture_codenames_preferred}) data = { "name": Tradegood.tradegood_lang2name(tradegood, lang), "category": Tradegoodcategory.tradegoodcategory2str(category) if category else None, "tradegoodtype": Tradegoodtype.tradegoodtype_lang2name(tgt, lang) if tgt else None, "ports_selling": ports2str(ports_selling), "cultures_preferred": culture_codenames2str(culture_codenames_preferred), "ports_preferred_resistant": ports2str(port_list_preferred_resistant), } text_out = str2strip(HenriqueJinja2.textfile2text(filepath, data)) return text_out