import sys import json from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[2] # 往上两级就是项目根 sys.path.insert(0, str(PROJECT_ROOT)) from pre_data.common.client_tools import write_jinja,del_jinja,write_multi_key,write_multi_common_key type_id ="201c51890c31c308050100218008390000000000000000000000000000000040" zone_ids=["2","3"] rectype_ids=["1","2"] popular_ids=["1"] custom_ids=["2"] # 通用模板?如果洗衣机干衣机都一样怎么处理 # key_common = "broadcast-template-jinja:"+type_id+":common" value_common_second_key="broadcast-template-jinja:single_card:wash:common" value_common = """ {% macro count_round(value) %} {% set value = value | int %} {{ (value / 10) | round(0) | int * 10 }} {% endmacro %} {% macro approx_fraction(p) -%} {%- set p = 99 if p |int >= 100 else p -%} {%- if p >= 50 -%} 百分之{{ ['','一','二','三','四','五','六','七','八','九'][p//10] }}{{ '十' if p >= 10 else '' }}{{ ['','一','二','三','四','五','六','七','八','九'][p%10] if p%10 else '' }} {%- elif p >= 40 -%}一半 {%- else -%}三分之一 {%- endif -%} {%- endmacro %} {% set greeting = ["嗨", "哈喽"] %} {% set assistant1 = ["小优来啦", "你的洗护小管家来啦", "你的洗护小助手来啦", "你的洗护小精灵来啦", "你的洗护小管家上线啦", "你的洗护小助手上线啦", "你的洗护小精灵上线啦", "小优前来报到", "洗护小管家前来报道", "洗护小助手前来报道", "洗护小精灵前来报到"] %} {% set assistant2 = ["洗衣推荐来啦", "洗衣小贴士来啦", "又要洗衣服啦", "又来洗衣服啦", "洗衣时间到啦"] %} {% set user1 = [ "位用户", "位邻居", "位朋友", "户家庭", "个小伙伴"] %} {% set user2 = ["用户", "小伙伴", "邻居"] %} {%- macro commands_params(changed_params) -%} {%- if changed_params is none or changed_params == {} or changed_params == "" -%} {{ "" }} {%- else -%} {# 注意:不要用 or 取值,因为 0 会被当成 false #} {%- set setTemp_raw = changed_params['setTemp'] if 'setTemp' in changed_params else changed_params.get('温度') -%} {%- set speed_raw = changed_params['speed'] if 'speed' in changed_params else changed_params.get('转速') -%} {%- set spinTime_raw = changed_params['spinTime'] if 'spinTime' in changed_params else changed_params.get('漂洗') -%} {%- set washTime_raw = changed_params['washTime'] if 'washTime' in changed_params else changed_params.get('时间') -%} {# ================= 温度 ================= #} {%- set temp_str = "" -%} {%- if setTemp_raw is not none and setTemp_raw != "" -%} {%- set setTemp_s = setTemp_raw|string|trim -%} {%- if setTemp_raw is number or setTemp_s.isdigit() -%} {%- set setTemp = setTemp_raw|int -%} {%- if setTemp != 65535 -%} {%- if setTemp == 0 -%} {%- set temp_str = "水温常温" -%} {%- elif setTemp >= 90 -%} {%- set temp_str = "水温95度" -%} {%- else -%} {%- set temp_str = "水温{}度".format(setTemp) -%} {%- endif -%} {%- endif -%} {%- else -%} {%- set temp_str = "水温" ~ setTemp_s -%} {%- endif -%} {%- endif -%} {# ================= 转速 ================= #} {%- set speed_str = "" -%} {%- if speed_raw is not none and speed_raw != "" -%} {%- set speed_s = speed_raw|string|trim -%} {%- if speed_raw is number or speed_s.isdigit() -%} {%- set speed = speed_raw|int -%} {%- if speed not in [65535] -%} {%- set speed_str = "转速{}转".format(speed * 10) -%} {%- endif -%} {%- else -%} {%- set speed_str = "转速" ~ speed_s -%} {%- endif -%} {%- endif -%} {# ================= 漂洗 ================= #} {%- set spin_str = "" -%} {%- if spinTime_raw is not none and spinTime_raw != "" -%} {%- set spinTime_s = spinTime_raw|string|trim -%} {%- if spinTime_raw is number or spinTime_s.isdigit() -%} {%- set spinTime = spinTime_raw|int -%} {%- if spinTime != 65535 -%} {%- set spin_str = "漂洗{}次".format(spinTime) -%} {%- endif -%} {%- else -%} {%- set spin_str = "漂洗" ~ spinTime_s -%} {%- endif -%} {%- endif -%} {# ================= 洗涤时间 ================= #} {%- set wash_str = "" -%} {%- if washTime_raw is not none and washTime_raw != "" -%} {%- set washTime_s = washTime_raw|string|trim -%} {%- if washTime_raw is number or washTime_s.isdigit() -%} {%- set washTime = washTime_raw|int -%} {%- if washTime not in [0, 65535] and washTime <= 255 -%} {%- set wash_str = "洗涤{}分钟".format(washTime) -%} {%- endif -%} {%- else -%} {%- set wash_str = "洗涤" ~ washTime_s -%} {%- endif -%} {%- endif -%} {{ [spin_str, wash_str, temp_str, speed_str] | reject("equalto", "") | join(",") }} {%- endif -%} {%- endmacro -%} {# --------------------- 人气/定制简短模板函数 --------------------- #} {% set prefix_message %} {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {% if program_name %} {% if rerank_reason |upper == "PIN_CONSECUTIVE" %} {%set commands_text = commands_params(changed_params) | trim %} {{[ "{0}好呀,小优发现你最近几次洗衣都喜欢用{1}程序,{2}给你准备好了。".format(period, program_name, commands_text~"这个使用习惯" if commands_text else ""), "{0},发现你最近几次洗衣都使用{1},{2}给你准备好了。".format(assistant1 | random, program_name, commands_text~"," if commands_text else ""), "{0},为你推荐最近几次常用的{1}程序,{2}赶快启动吧!".format(assistant2 | random, program_name, commands_text~"," if commands_text else ""), "{0},最懂你的小优来啦,你最近几次洗衣都使用了{1}程序,{2}这次还这么用吧。".format(greeting |random, program_name, commands_text~"," if commands_text else ""), "又能帮你洗衣服了,小优很开心哦。前几次洗衣你都使用{0}程序,我猜你这次还想用它。".format(program_name) ] | random }} {% elif rerank_reason |upper == "PIN_WEEKLY" %} {%set feature_week_name="每周这个时间都喜欢用"%} {%set commands_text = commands_params(changed_params) | trim %} {{[ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format(period, feature_week_name, program_name, commands_text~"," if commands_text else ""), "{0}好呀,小优准备了你{1}的{2}程序。{3}快来启动吧。".format(period, feature_week_name, program_name, commands_text~"," if commands_text else ""), "{0},{1},推荐你{2}的{3}程序。{4}".format(greeting |random, assistant1 | random, feature_week_name, program_name, commands_text~"。" if commands_text else ""), "{0},你{1}的{2}程序,{3}给你准备好了。".format(assistant1 | random, feature_week_name, program_name, commands_text~"这个使用习惯" if commands_text else ""), "{0},小优准备了你{1}的{2}程序,{3}赶快启动吧!".format(assistant2 | random, feature_week_name, program_name, commands_text~"," if commands_text else "") ] | random}} {% elif recommend_type |upper == "POPULAR" %} {{ [ "{0},给你准备了{1}人气最高的{2}程序。".format(assistant1 | random, city, program_name), "{0},这个时间{1}程序在{2}使用率最高哦。".format(assistant2 | random, program_name, city), "{0}好呀,为你推荐{1}人气最高的{2}程序。".format(period, city, program_name), "嗨,小优发现这个时间{0},{1}程序人气最高哦。".format(city, program_name), "{0}洗衣推荐来啦,{1}程序是{2}当前的热门程序哦。".format(season, program_name, city) ] | random }} {% elif recommend_type |upper == "CUSTOM" %} {%set commands_text = commands_params(changed_params) | trim %} {% if feature_name!="" %} {{ [ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format(period, feature_name, program_name, commands_text~"," if commands_text else ""), "{0}好呀,小优准备了你{1}的{2}程序。{3}".format(period, feature_name, program_name, commands_text~"。" if commands_text else ""), "{0},推荐你{1}的{2}程序。{3}".format(assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else ""), "{0},为你准备了你{1}的{2}程序。{3}".format(assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else ""), "{0},你{1}的{2}程序,{3}已经准备就绪。".format(assistant2 | random, feature_name, program_name, commands_text if commands_text else "") ]| random }} {% else %} {{ "您好,推荐您常用的{}程序,已准备好了,快开始启动吧。".format(program_name) }} {% endif %} {% endif %} {% else %} 抱歉,ID为'{{ program_id }}'的程序不存在或暂未收录。 {% endif %} {% endset %} """ value_popular_second_key="broadcast-template-jinja:single_card:wash:time_popular" # 人气模板 # def key_popular_fun(zone_id:str): # return "broadcast-template-jinja:"+type_id+":"+zone_id+":time_made_popularity:1" value_popular = """ {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {% set count = count_round(count) | int %} {% set user_count = count_round(user_count) |int %} {% set user_proportion = user_proportion | int %} {% if program_name %} {% if rerank_reason |upper == "PIN_CONSECUTIVE" %} {%set commands_text = commands_params(changed_params) | trim %} {{[ "{0}好呀,小优发现你最近几次洗衣都喜欢用{1}程序,{2}给你准备好了。".format(period, program_name, commands_text~"这个使用习惯" if commands_text else "" ), "{0},发现你最近几次洗衣都使用{1},{2}给你准备好了。".format(assistant1 | random, program_name, commands_text~"," if commands_text else "" ), "{0},为你推荐最近几次常用的{1}程序,{2}赶快启动吧!".format(assistant2 | random, program_name, commands_text~"," if commands_text else "" ), "{0},最懂你的小优来啦,你最近几次洗衣都使用了{1}程序,{2}这次还这么用吧。".format(greeting |random, program_name, commands_text~"," if commands_text else "" ), "又能帮你洗衣服了,小优很开心哦。前几次洗衣你都使用{0}程序,我猜你这次还想用它。".format( program_name ) ] | random }} {% elif rerank_reason |upper == "PIN_WEEKLY" %} {%set commands_text = commands_params(changed_params) | trim %} {%set feature_week_name="每周这个时间都喜欢用"%} {{[ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format( period, feature_week_name, program_name, commands_text~"," if commands_text else "" ), "{0}好呀,小优准备了你{1}的{2}程序。{3}快来启动吧。".format( period, feature_week_name, program_name, commands_text~"," if commands_text else "" ), "{0},{1},推荐你{2}的{3}程序。{4}".format( greeting |random, assistant1 | random, feature_week_name, program_name, commands_text~"。" if commands_text else "" ), "{0},你{1}的{2}程序,{3}给你准备好了。".format( assistant1 | random, feature_week_name, program_name, commands_text~"这个使用习惯" if commands_text else "" ), "{0},小优准备了你{1}的{2}程序,{3}赶快启动吧!".format( assistant2 | random, feature_week_name, program_name, commands_text~"," if commands_text else "" ) ] | random}} {% else %} {{ [ "{0}好呀,为你推荐{1}人气最高的{2}程序。{3}".format( period, city, program_name, ("近期有" ~ user_count ~ "多" ~ (user1 | random) ~ "都喜欢用呢。" if user_count >= 30 else "") ), "{0}好呀,为你推荐{1}人气最高的{2}程序。{3}".format( period, city, program_name, ("近期有" ~ approx_fraction(user_proportion) ~ "的" ~ (user2 | random) ~ "都喜欢用呢。" if user_proportion >= 30 else "快启动试试吧。") ), "{0}好呀,小优发现{1}程序在{2}的人气很高哦,{3}咱也来试试吧!".format( period, program_name, city, ("近期有" ~ count ~"多次使用记录呢," if count >= 100 else "") ), "{0},给你准备了{1}人气最高的{2}程序,{3}".format( assistant1 |random, city, program_name, ("近期有"~ user_count ~"多" ~ (user1 | random) ~ "都喜欢用呢。咱们也来试试看吧!" if user_count >= 30 else "快来试试看吧!") ), "{0},{1}程序在{2}很受欢迎呢,{3}咱们也来试试看吧!".format( assistant1 |random, program_name, city, ("是" ~ user_count ~"多"~ (user1 | random) ~ "的共同选择。" if user_count >= 30 else "") ), "{0},{1},这个时间段{2}程序在{3}人气最高,{4}给你也准备好了。".format( greeting | random, assistant1 | random, program_name, city, ("超过" ~ approx_fraction(user_proportion) ~ "的" ~ (user2 |random) ~ "都在用呢," if user_proportion >= 30 else "") ), "{0},为你推荐当前人气最高的{1}程序,{2}".format( assistant2 | random, program_name, (city ~ "超过"~ approx_fraction(user_proportion) ~"的"~ (user2 |random) ~"都在用哦" if user_proportion >= 30 else "都准备好了,直接启动就行。") ), "{0},给你准备了{1}人气最高的{2}程序,{3}".format( assistant2 | random, city, program_name, ("近期有"~ user_count ~"多" ~ (user1 | random) ~ "都喜欢用呢。咱们也来试试看吧!" if user_count >= 30 else "快启动试试吧!") ), "{0},{1}程序在{2}人气最高,{3}咱们也来试试看吧!".format( assistant2 | random, program_name, city, ("是"~ user_count ~"多"~ (user1 | random) ~ "的共同选择。" if user_count >= 30 else "") ), "{0},{1},{2}程序给你准备好了,{3}快来试试看吧!".format( greeting | random, assistant2 | random, program_name, ("这个时间"~ city ~"有超过"~ approx_fraction(user_proportion) ~"的"~ (user2 |random) ~"都在用它," if user_proportion >= 30 else "") ), "{0}好呀,根据全网用户的使用偏好,我帮你选好了{1}程序,你放心用就好了。".format( period, program_name ), "{0}好呀,小优发现大家都爱用{1}程序,今天我们也来试试吧。".format( period, program_name ), "{0},为你准备好了全网使用率最高的{1}程序,来试试效果怎么样吧。".format( assistant1 | random, program_name ), "{0}!{1},{2}程序大家用着还不错,快启动体验一下吧。".format( greeting | random, assistant2 | random, program_name ), "{0}!{1},今天我们来试试这个人气最高的程序吧。".format( greeting | random, assistant2 | random ) ] | random }} {% endif %} {% else %} 抱歉,ID为'{{ program_id }}'的程序不存在或暂未收录。 {% endif %} """ # 定制模板 value_custom_second_key="broadcast-template-jinja:single_card:wash:time_custom" # def key_custom_fun(zone_id:str): # return "broadcast-template-jinja:"+type_id+":"+zone_id+":time_made_popularity:2" value_custom=""" {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {% if program_name %} {%set commands_text = commands_params(changed_params) | trim %} {% if rerank_reason |upper == "PIN_CONSECUTIVE" %} {{[ "{0}好呀,小优发现你最近几次洗衣都喜欢用{1}程序,{2}给你准备好了。".format(period, program_name, commands_text~"这个使用习惯" if commands_text else "" ), "{0},发现你最近几次洗衣都使用{1},{2}给你准备好了。".format(assistant1 | random, program_name, commands_text~"," if commands_text else "" ), "{0},为你推荐最近几次常用的{1}程序,{2}赶快启动吧!".format(assistant2 | random, program_name, commands_text~"," if commands_text else "" ), "{0},最懂你的小优来啦,你最近几次洗衣都使用了{1}程序,{2}这次还这么用吧。".format(greeting |random, program_name, commands_text~"," if commands_text else "" ), "又能帮你洗衣服了,小优很开心哦。前几次洗衣你都使用{0}程序,我猜你这次还想用它。".format( program_name ) ] | random }} {% elif rerank_reason |upper == "PIN_WEEKLY" %} {%set feature_week_name="每周这个时间都喜欢用"%} {{[ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format( period, feature_week_name, program_name, commands_text~"," if commands_text else "" ), "{0}好呀,小优准备了你{1}的{2}程序。{3}快来启动吧。".format( period, feature_week_name, program_name, commands_text~"," if commands_text else "" ), "{0},{1},推荐你{2}的{3}程序。{4}".format( greeting |random, assistant1 | random, feature_week_name, program_name, commands_text~"。" if commands_text else "" ), "{0},你{1}的{2}程序,{3}给你准备好了。".format( assistant1 | random, feature_week_name, program_name, commands_text~"这个使用习惯" if commands_text else "" ), "{0},小优准备了你{1}的{2}程序,{3}赶快启动吧!".format( assistant2 | random, feature_week_name, program_name, commands_text~"," if commands_text else "" ) ] | random}} {% elif feature_name!="" %} {{ [ "{0}好呀,小优发现你{1}{2}程序,{3}给你准备好了。".format( period, feature_name, program_name, commands_text~"," if commands_text else "" ), "{0}好呀,小优准备了你{1}的{2}程序。{3}快来启动吧".format( period, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0}好呀,{1}程序已经准备就绪了,它可是你{2}的程序。{3}赶快启动吧".format( period, program_name, feature_name, commands_text~"的习惯参数也帮你设置好了。" if commands_text else "" ), "{0},{1},推荐你{2}的{3}程序,{4}".format( greeting | random, assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0},{1},为你准备了你{2}的{3}程序。{4}".format( greeting | random, assistant1 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0},你{1}的{2}程序{3}".format( assistant2 | random, feature_name, program_name, "和"~commands_text~"的习惯参数给你准备好了。" if commands_text else ",给你准备好了。" ), "{0},为你推荐{1}的{2}程序,{3}赶快启动吧!".format( assistant2 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "{0},你{1}的{2}程序,{3}已经准备就绪。启动前,记得检查衣物口袋哦。".format( assistant2 | random, feature_name, program_name, commands_text~"。" if commands_text else "" ), "我发现你喜欢这么用,我给你准备好了,现在开始洗吗?", "你懂洗衣,我懂你,准备好了,快开始洗吧。" ]| random }} {% else %} {{ "您好,推荐您常用的{}程序,已准备好了,快开始启动吧。".format(program_name) }} {% endif %} {% else %} 抱歉,ID为'{{ program_id }}'的程序不存在或暂未收录。 {% endif %} """ # 天气模板--二级key value_weather_second_key="broadcast-template-jinja:single_card:wash:time_weather" value_weather = """ {% set wd_link = wd_link | string |trim %} {% if wd_link in ['1', '开'] %} {% set wd_link = '1' %} {% endif %} {% set washdry = washdry | string |trim %} {{ [ prefix_message |trim, [ "今天阴天,洗完烘干更省心哦。" if weather == '阴' else "天气预报今天有{},洗完烘干更省心哦。".format(weather) if weather in ['小雨','中雨','大雨','暴雨','小雪','中雪','大雪','暴雪','雾霾','中度雾霾','重度雾霾','沙尘'] else "今天天气不太好,洗完烘干更省心哦。" ] | first if washdry == "_wd" else [ [ "今天阴天,晾晒衣物会比较慢,帮你打开洗烘联动啦。", "今天阴天,晾晒衣物会比较慢,洗烘联动更省心哦。" ] | random if weather == '阴' and wd_link == "1" else "今天阴天,室外晾晒衣物会比较慢,建议您在室内晾晒。" if weather == '阴' else [ "今天预报有{},不适合室外晾晒,帮你打开洗烘联动啦。".format(weather), "今天预报有{},不适合室外晾晒,洗烘联动更省心哦。".format(weather) ] | random if weather in ['小雨','中雨','大雨','暴雨','小雪','中雪','大雪','暴雪'] and wd_link == "1" else "天气预报今天有{},建议您在室内晾晒。".format(weather) if weather in ['小雨','中雨','大雨','暴雨','小雪','中雪','大雪','暴雪'] else [ "今天有{},室外晾晒容易导致二次污染,帮你打开洗烘联动啦。".format(weather), "今天有{},室外晾晒容易导致二次污染,洗烘联动更省心哦。".format(weather) ] | random if weather in ['雾霾','中度雾霾','重度雾霾','沙尘'] and wd_link == "1" else "天气预报今天有{},室外晾晒容易导致二次污染,建议您在室内晾晒。".format(weather) if weather in ['雾霾','中度雾霾','重度雾霾','沙尘'] else [ "今天天气不太好,帮你打开洗烘联动啦。", "今天天气不太好,洗烘联动更省心哦。" ] | random if wd_link == "1" else "今天天气不太好,建议您在室内晾晒。" ] | first ]| reject("equalto", "") | join("") }} """ #=====季节模板 value_season_second_key="broadcast-template-jinja:single_card:wash:time_season" value_season=""" {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {{ [ "立春快乐,春风送暖,是时候准备好轻盈的春装了。{}".format( "为您推荐"~program_name~"程序,应对春季多变天气,轻松打理出行装备。" if program_id == '52' else "") if time_term == '立春' and filter_rule_code== 'time_season_in' else "立春时节,是时候让厚重冬衣退役啦。{}".format( "为您推荐"~program_name~"程序,温和洗净,将暖意封存。" if program_id in ["3","10"] else "") if time_term == '立春' and filter_rule_code== 'time_season_storage' else "立夏时节,暑气渐长。轻薄的夏日穿搭该从箱底翻出来洗洗啦。{}".format( "为您推荐"~program_name~"程序,温和洗净,抚平褶皱,让您的夏日清爽舒适。" if program_id in ["22","1"] else "") if time_term == '立夏' and filter_rule_code== 'time_season_in' else "立夏潮闷,春装收纳正当时。{}".format( "推荐使用"~program_name~"程序,彻底洗净风尘,便于安心久存。" if program_id == '52' else "") if time_term == '立夏' and filter_rule_code== 'time_season_storage' else "立秋已至,暑去凉来。是时候洗净压箱底的秋装,准备添衣了。{}".format( "为您推荐"~program_name~"程序,温和洁净,守护面料防水与防风性能,伴您从容出行。" if program_id == '52' else "") if time_term == '立秋' and filter_rule_code== 'time_season_in' else "立秋换季,夏装可以功成身退啦。{}".format( "推荐使用"~program_name~"程序,温和洗净,防止变形与泛黄,帮您留住夏日风采。" if program_id in ["22","1"] else "") if time_term == '立秋' and filter_rule_code== 'time_season_storage' else "立冬安康,寒潮将至。保暖的冬装该登场了。{}".format( "为您推荐"~program_name~"程序,温和洁净,让衣物恢复蓬松柔软,为您锁住冬日温暖。" if program_id in ["3","10"] else "") if time_term == '立冬' and filter_rule_code== 'time_season_in' else "立冬时节,薄款秋装该收纳入库啦。{}".format( "为您推荐"~program_name~"程序,温和洁净,让您的衣物保持最佳状态,静待明年春日。" if program_id == '52' else "") if time_term == '立冬' and filter_rule_code== 'time_season_storage' ]| random}} """ #关怀模板 value_care_second_key="broadcast-template-jinja:single_card:wash:time_care" value_care = """ {# 从归一化后的 care 字典中读取,active = 1 表示已开启 #} {% set night_wash_on = care.get("night_wash", {}).get("active", 0) == 1 %} {% set night_wash_name = care.get("night_wash", {}).get("display_name", "夜间洗") %} {% set wind_cruise_on = care.get("wind_cruise", {}).get("active", 0) == 1 %} {% set wind_cruise_name = care.get("wind_cruise", {}).get("display_name", "风巡航") %} {{ [prefix_message |trim, [ ["夜深了,帮你打开{0}和{1}功能啦。".format(night_wash_name, wind_cruise_name) , "时间有点晚了,已为你开启{0}和{1},衣物久放也不闷。".format(night_wash_name, wind_cruise_name), "{0}已开启,静音洗衣,{1}为您守护衣物至天明。".format(night_wash_name, wind_cruise_name), "已开启{0}自动降噪,并开启{1}防异味。".format(night_wash_name, wind_cruise_name) ] |random if night_wash_on and wind_cruise_on else ["夜深了,帮你打开{0}功能,静音不扰眠。".format(night_wash_name), "时间有点晚了,我会静悄悄的。", "夜间洗衣,已自动开启静音洗涤,守护您的安宁。", "夜洗功能也准备好了,洗衣机会低噪运行,让您静享安宁。" ] |random if night_wash_on else ["夜深了,帮你打开{},智能保管衣物。".format(wind_cruise_name) , "时间有点晚了,{}功能可以帮你守护衣物到天明。".format(wind_cruise_name), "夜间洗衣,帮你开启{}了,衣物久放也不用怕。".format(wind_cruise_name), "{}也准备好了,洗完会帮你智能保管衣物。".format(wind_cruise_name) ]|random if wind_cruise_on else "" ] | first] | reject("equalto", "") | join("") }} """ #=====环保模板 value_env_second_key="broadcast-template-jinja:single_card:wash:time_environmental" value_env=""" {{ [prefix_message |trim,"马上就到错峰用电时间段了,建议您预约洗护。"] |reject("equalto", "") | join("")}} """ #====健康模板 value_health_second_key="broadcast-template-jinja:single_card:wash:time_health" value_health=""" {% set program_id = program_id | string | trim %} {% set program_name = program_name_map.get(program_id) %} {{"你的洗衣机该清洁了,快启用{}程序给它洗个澡吧!注意不要放入衣服和洗衣液哦。".format(program_name)}} """ #====健康2模板——杀菌 value_health2_second_key="broadcast-template-jinja:single_card:wash:time_health_2" value_health2=""" {% set health2_features = health2_features | string | trim %} {{"最近天气湿度较高,帮你打开了{}功能,杀菌消毒更放心哦。".format(health2_features)}} """ #================ 写入X11洗衣机模板========================================== # 通用 # write_multi_common_key(type_id, zone_ids, value_common_second_key) write_jinja(value_common_second_key, value_common, notify=True) # 人气 # write_multi_key("time_made_popularity", zone_ids, popular_ids, type_id, value_popular_second_key) write_jinja(value_popular_second_key,value_popular, notify=True) # # 定制 # write_multi_key("time_made_popularity", zone_ids, custom_ids, type_id, value_custom_second_key) write_jinja(value_custom_second_key,value_custom, notify=True) # 天气 # 写入多个指向同一个key # write_multi_key("time_weather", zone_ids, rectype_ids, type_id, value_weather_second_key) write_jinja(value_weather_second_key,value_weather, notify=True) # # 季节 # write_multi_key("time_season_storage", zone_ids, rectype_ids, type_id, value_season_second_key) # write_multi_key("time_season_in", zone_ids, rectype_ids, type_id, value_season_second_key) write_jinja(value_season_second_key,value_season, notify=True) # # 关怀 # write_multi_key("time_care", zone_ids, rectype_ids, type_id, value_care_second_key) write_jinja(value_care_second_key,value_care, notify=True) # 环保 # write_multi_key("time_environmental", zone_ids, rectype_ids, type_id, value_env_second_key) write_jinja(value_env_second_key,value_env, notify=True) # # 健康 # write_multi_key("time_health", zone_ids, rectype_ids, type_id, value_health_second_key) write_jinja(value_health_second_key,value_health, notify=True) # 健康2杀菌 # write_multi_key("time_health_2", zone_ids, rectype_ids, type_id, value_health2_second_key) write_jinja(value_health2_second_key,value_health2, notify=True)