def edit_rules(): """Edit rules Edit the rules that process inbound events""" my_rules = rules.get_all_rules() my_rules.append(DEFAULT_RULE) selected_rule_id = select( label="Existing rules", options=[{ "label": rule["name"], "value": rule["id"] } for rule in my_rules], ) # Rules have unique IDs from the database: logging.info(f"selected_rule: {selected_rule_id}") use_rule = [r for r in my_rules if r["id"] == int(selected_rule_id)][0] updated_rule = input_group( "Rule editing", [ input("name", type=TEXT, name="name", value=use_rule["name"], required=True), # Need ttextarea( textarea( "Rule names", name="rule", rows=10, code={ "mode": "python", # code language "theme": "darcula", # Codemirror theme. Visit https://codemirror.net/demo/theme.html#cobalt to get more themes }, value=f"""{use_rule['rule']}\n""", ), actions( "actions", [ # {"label": "test", "value": "test"}, { "label": "save", "value": "save" }, ], name="action", help_text="Save", ), ], ) if updated_rule is not None: rl = dict(updated_rule) if rl["action"] == "save": rule_info = rules.save_rule(rl["name"], rl["rule"], selected_rule_id) put_row(put_text("Rule")) put_row(put_code(pprint.pformat(rule_info, indent=1))) # Use webhook_info's ID to add/update the extractor put_text(f"The rule added is: {updated_rule}")
def collatz(initial_number): number_list = array('i', []) try: number = int(initial_number) if number < 0: put_text("Number must be greater than zero") number_getter() number_list.append(number) while number != 1: if number % 2 == 0: number = number // 2 number_list.append(number) else: number = 3 * number + 1 number_list.append(number) else: number_list.append(number) put_text( f"Seed number: {initial_number}.\nLargest number in sequence was {max(number_list)}\n" f"It took {len(number_list)-2} iterations to reach the number 1\n\n" ) put_html(make_graph(number_list)) number_getter() except ValueError: number_getter()
def sontop_pc(x=10): global quyi, yuqori, taxmin quyi = 1 yuqori = x put_text(f"1 dan {x} gacha son o'ylang.\nSizga 3 soniya vaqt!") for i in [3, 2, 1, 'Boshladik!']: put_text(str(i)) sleep(1) def guess(): pywebio.output.clear(scope=-1) global taxmin taxmin = random.randint(quyi, yuqori) put_text(f"Siz {taxmin} sonini o'yladingiz!") put_buttons(['Kattaroq', 'Togri', 'Kichikroq'], onclick=[katta, bingo, kichik]) pywebio.session.hold() def kichik(): global yuqori yuqori = taxmin - 1 guess() def katta(): global quyi quyi = taxmin + 1 guess() def bingo(): put_text("Men yutdim!") guess()
def show(self) -> None: self._show() self.init_aside(name="Home") self.set_aside() self.collapse_menu() self.alas_name = "" if hasattr(self, "alas"): del self.alas self.set_status(0) def set_language(l): lang.set_language(l) self.show() def set_theme(t): self.set_theme(t) run_js("location.reload()") with use_scope("content"): put_text("Select your language / 选择语言").style("text-align: center") put_buttons( [ {"label": "简体中文", "value": "zh-CN"}, {"label": "繁體中文", "value": "zh-TW"}, {"label": "English", "value": "en-US"}, {"label": "日本語", "value": "ja-JP"}, ], onclick=lambda l: set_language(l), ).style("text-align: center") put_text("Change theme / 更改主题").style("text-align: center") put_buttons( [ {"label": "Light", "value": "default", "color": "light"}, {"label": "Dark", "value": "dark", "color": "dark"}, ], onclick=lambda t: set_theme(t), ).style("text-align: center") # show something put_markdown( """ Alas is a free open source software, if you paid for Alas from any channel, please refund. Alas 是一款免费开源软件,如果你在任何渠道付费购买了Alas,请退款。 Project repository 项目地址:`https://github.com/LmeSzinc/AzurLaneAutoScript` """ ).style("text-align: center") if lang.TRANSLATE_MODE: lang.reload() def _disable(): lang.TRANSLATE_MODE = False self.show() toast( _t("Gui.Toast.DisableTranslateMode"), duration=0, position="right", onclick=_disable, )
def update_table(): with use_scope("updater_info", clear=True): local_commit = updater.get_commit(short_sha1=True) upstream_commit = updater.get_commit( f"origin/{updater.Branch}", short_sha1=True ) put_table( [ [t("Gui.Update.Local"), *local_commit], [t("Gui.Update.Upstream"), *upstream_commit], ], header=[ "", "SHA1", t("Gui.Update.Author"), t("Gui.Update.Time"), t("Gui.Update.Message"), ], ) with use_scope("updater_detail", clear=True): put_text(t("Gui.Update.DetailedHistory")) history = updater.get_commit( f"origin/{updater.Branch}", n=20, short_sha1=True ) put_table( [commit for commit in history], header=[ "SHA1", t("Gui.Update.Author"), t("Gui.Update.Time"), t("Gui.Update.Message"), ], )
def guess(): pywebio.output.clear(scope=-1) global taxmin taxmin = random.randint(quyi, yuqori) put_text(f"Siz {taxmin} sonini o'yladingiz!") put_buttons(['Kattaroq', 'Togri', 'Kichikroq'], onclick=[katta, bingo, kichik]) pywebio.session.hold()
def index(): print("run") put_text("12345") out = output() put_scrollable(out, keep_bottom=True) while True: il = input_group("233", [input(name="aaa", value="23456")]) outp(out, il)
def app(): pages = get_pages() text_info = customize_text() save_location = input("What is the name of your PDF file?", required=True) create_pdf(pages, font='Arial', size=16, save_location=save_location) put_text("Congratulations! A PDF file is generated for you.")
def guess(self): self.__taxminlar += 1 yuqori = self.__yuqori quyi = self.__quyi pywebio.output.clear(scope=- 1) self.__taxmin = random.randint(quyi, yuqori) put_text(f"Siz {self.__taxmin} sonini o'yladingiz!") put_buttons(['Kattaroq','Togri','Kichikroq'], onclick=[self.katta, self.bingo,self.kichik]) pywebio.session.hold()
def set_status(self, state: int) -> None: """ Args: state (int): 1 (running) 2 (not running) 3 (warning, stop unexpectedly) 4 (stop for update) 0 (hide) -1 (*state not changed) """ if state == -1: return clear() if state == 1: put_row( [ put_loading(color="success").style("--loading-border--"), None, put_text(t("Gui.Status.Running")), ], size="auto 2px 1fr", ) elif state == 2: put_row( [ put_loading(color="secondary").style("--loading-border-fill--"), None, put_text(t("Gui.Status.Inactive")), ], size="auto 2px 1fr", ) elif state == 3: put_row( [ put_loading(shape="grow", color="warning").style( "--loading-grow--" ), None, put_text(t("Gui.Status.Warning")), ], size="auto 2px 1fr", ) elif state == 4: put_row( [ put_loading(shape="grow", color="success").style( "--loading-grow--" ), None, put_text(t("Gui.Status.Updating")), ], size="auto 2px 1fr", )
def put_task(func: Function): with use_scope(f'overview-task_{func.command}'): put_column([ put_text( t(f'Task.{func.command}.name')).style("--arg-title--"), put_text(str(func.next_run)).style("--arg-help--"), ], size="auto auto") put_button(label=t("Gui.Button.Setting"), onclick=lambda: self.alas_set_group(func.command), color="off")
def main(): set_env(title="FlyOS Panel", auto_scroll_bottom=True) put_html("<h1>FlyOS WEB Panel</h1>") put_text('FlyOS RunShellTool By:XingYuJie', sep=' ') runshell = pywebio.input.input("Shell终端命令执行" "请输入要执行的命令(会在后台执行):") fastrun = pywebio.input.input("FlyOS快速运行程序(已在FlyOS环境下):") #启动FlyOSfastrun os.system("python $FLYOS" + fastrun) print("你输入的命令(结果在下方): %s" % runshell) #使用runshell os.system(runshell)
def main(): set_env(title="Linux 部署程序--中文版", auto_scroll_bottom=True) put_html("<h1>FlyOS Linux Deploy</h1>") put_text("By:FlyOS MicroTech XingYuJie(严禁删除版权,不允许修改版权)GPL-V3", sep=" ") popup( "欢迎使用Linux部署程序--中文版", "欢迎使用Linux部署程序--中文版。" "开始部署你的Linux吧!" "程序由MicroTech Projects -- FlyOS强力驱动", ) Main()
def bmi(): height = input("请输入你的身高(cm):", type=FLOAT) weight = input("请输入你的体重(kg):", type=FLOAT) BMI = weight / (height / 100)**2 top_status = [(14.9, '极瘦'), (18.4, '偏瘦'), (22.9, '正常'), (27.5, '过重'), (40.0, '肥胖'), (float('inf'), '非常肥胖')] for top, status in top_status: if BMI <= top: put_text('你的 BMI 值: %.1f,身体状态:%s' % (BMI, status)) break
def set_group(self, group, arg_dict, config, task): group_name = group[0] with use_scope(f'group_{group_name}'): put_text(t(f"{group_name}._info.name")) group_help = t(f"{group_name}._info.help") if group_help != "": put_text(group_help) put_html('<hr class="hr-group">') for arg, d in deep_iter(arg_dict, depth=1): arg = arg[0] arg_type = d['type'] if arg_type == 'disable': continue value = deep_get(config, f'{task}.{group_name}.{arg}', d['value']) value = str(value) if isinstance(value, datetime) else value # Option options = deep_get(d, 'option', None) if options: option = [] for opt in options: o = { "label": t(f"{group_name}.{arg}.{opt}"), "value": opt } if value == opt: o["selected"] = True option.append(o) else: option = None # Help arg_help = t(f"{group_name}.{arg}.help") if arg_help == "" or not arg_help: arg_help = None # Invalid feedback invalid_feedback = t("Gui.Text.InvalidFeedBack").format( d['value']) get_output( arg_type=arg_type, name=self.path_to_idx[f"{task}.{group_name}.{arg}"], title=t(f"{group_name}.{arg}.name"), arg_help=arg_help, value=value, options=option, invalid_feedback=invalid_feedback, ).show()
def bmi(): height = input("Your Height(cm):", type=FLOAT) weight = input("Your Weight(kg):", type=FLOAT) BMI = weight / (height / 100)**2 top_status = [(14.9, 'Severely underweight'), (18.4, 'Underweight'), (22.9, 'Normal'), (27.5, 'Overweight'), (40.0, 'Moderately obese'), (float('inf'), 'Severely obese')] for top, status in top_status: if BMI <= top: put_text('Your BMI: %.1f, category: %s' % (BMI, status)) break
def bmi(): height = input("Input your height(cm):", type=FLOAT) weight = input("Input your weight(kg):", type=FLOAT) BMI = weight / (height / 100)**2 top_status = [(16, 'Severely underweight'), (18.5, 'Underweight'), (25, 'Normal'), (30, 'Overweight'), (35, 'Moderately obese'), (float('inf'), 'Severely obese')] for top, status in top_status: if BMI <= top: put_text('Your BMI: %.1f. Category: %s' % (BMI, status)) break
async def get_result(cmd): """ params: cmd - 要执行的命令 """ popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, cwd=path) while True: buff = popen.stdout.readline() if buff: put_text(buff) elif popen.poll() is not None: break
def main(): """主方法""" if not os.path.exists(FLYOS_ROOT + "/.firstuse/lock"): set_env(title="欢迎使用FlyOS", auto_scroll_bottom=True) put_html("<h1>欢迎使用! -- FlyOS 初始化向导</h1>") put_text('欢迎使用FlyOS!开始初始化您的FlyOS吧!') popup('Hi,There!欢迎使用FlyOS!让我们来初始化FlyOS吧!') password = pywebio.input.input("设置您的系统密码:", type="password") vpwd = pywebio.input.input("请再次输入密码验证:", type="password") if password != vpwd: popup('错误', "两次输入密码不一致,请刷新页面重试") return put_text('初始化完成!请进入termuxAPP开始体验FlyOS吧!') termux_auth.change_passwd(password) os.mkdir(f"{HOME}/.flyos") os.kill(os.getpid(), 9)
def main(): set_env(title="FlyOS Devices API Tool", auto_scroll_bottom=True) put_html("<h1>FlyOS Devices API Tool</h1>") pwd = pywebio.input.input("输入flyos密码: ") if termux_auth.auth(pwd): while 1: api = pywebio.input.input("输入api调用接口:") if re.search('[;&|<>$]', api): popup('检测到非法字符', content="请检查命令中是否包含;&|等特殊字符") continue status, output = subprocess.getstatusoutput(f'termux-{api}') if status == 0: popup('命令已执行', output) else: popup('执行时出现错误', output) else: put_text("密码错误, 请刷新页面重试")
def main(): set_env(title="Linux 部署程序--中文版", auto_scroll_bottom=True) put_html("<h1>FlyOS Linux Deploy</h1>") put_text("By:FlyOS MicroTech XingYuJie(严禁删除版权,不允许修改版权)GPL-V3", sep=" ") popup( "欢迎使用Linux部署程序--中文版", "欢迎使用Linux部署程序--中文版。" "开始部署你的Linux吧!" "程序由MicroTech Projects -- FlyOS强力驱动", ) n = pywebio.input.select( "请选择你要执行的操作", options=[ ("安装Linux", 1, True), ("进入Linux", 2), ], ) if n == 1: name = pywebio.input.input("请输入该系统的名字") command = pywebio.input.radio( "请选择要用的命令", [ ("PRoot(无root下使用)", "proot -r ", True), ("chroot(有root建议使用)", "sudo chroot "), ], ) arch = subprocess.getoutput("dpkg --print-architecture") num = pywebio.input.select( "请选择你要安装的系统", options=[ ("Ubuntu", 1, True), ("CentOS", 2), ("Kali", 3), ], ) if num == 1: get_ubuntu(name, arch, command) elif num == 2: get_centos(name, arch, command) elif num == 3: get_kali(name, arch, command) elif n == 2: join() elif n == 3: delete()
def main(): set_env(title="FlyOS Phone Shell", auto_scroll_bottom=True) put_html("<h1>FlyOS WEB Phone Shell</h1>") put_text('FlyOS Phone Web Shell By:XingYuJie', sep=' ') pwd = pywebio.input.input("输入flyos密码:") if termux_auth.auth(pwd): while 1: command = pywebio.input.input("请输入AM参数加命令:") if re.search('[;&|<>$]', command): popup('检测到非法字符', content="请检查命令中是否包含;&|等特殊字符") continue status, output = subprocess.getstatusoutput("am " + command) if status == 0: popup('命令已执行', output) else: popup('命令执行时出现错误', output) else: put_text("密码错误,请刷新页面重试")
def main(): set_env(title="FlyOS Virtual Machine", auto_scroll_bottom=True) put_html("<h1>FlyOS WEB Virtual Machine</h1>") put_text('FlyOS Virtual Machine By:XingYuJie', sep=' ') popup( '欢迎使用FlyOS FlyOS Virtual Machine!', '欢迎使用FlyOS Virtual Machine。' '开始创建您的虚拟机吧!' '程序由MicroTech Projects -- FlyOS强力驱动') cpu = pywebio.input.input("请输入架构,例如i386架构:") path = pywebio.input.input("请输入虚拟机磁盘镜像完整绝对路径:") memory = pywebio.input.input("请输入虚拟机内存(不建议太大):") network = pywebio.input.input("请输入网卡驱动(建议rtl8139):") vga = pywebio.input.input("请输入显卡驱动(建议vmware):") vnc = pywebio.input.input("输入VNC端口号(建议0):") qemu = f"qemu-system-{cpu} " qemu += f"-hda {path} -m {memory} -device {network} " qemu += f"-vga {vga} -vnc :{vnc}" os.system(qemu)
def bmi4(): datos=pd.read_csv("original.csv",header=0) X=datos[['resid_area','air_qual','room_num','age','dist1','dist2','dist3','dist4']] Y=datos["price"] X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.3,random_state=42) lr=LinearRegression() lr.fit(X_train,Y_train) prediccion=lr.predict(X_test) resi=input("Ingresa el area",type=FLOAT) air=input("Ingresa el air_qual",type=FLOAT) room=input("Ingresa el room_num",type=FLOAT) age=input("Ingresa la edad del producto",type=FLOAT) dist1=input("Ingresa la dist1: ",type=FLOAT) dist2=input("Ingresa la dist2: ",type=FLOAT) dist3=input("Ingresa la dist3: ",type=FLOAT) dist4=input("Ingresa la dist4: ",type=FLOAT) resp=lr.predict([[resi,air,room,age,dist1,dist2,dist3,dist4]]) put_text("La respuesta es: " + str(resp))
def demo(): age = input("Enter your age: ", type=NUMBER) year_exp = input("Enter your years of experience: ", type=NUMBER) if (age >= 16 and age <=20) and (year_exp <=1): put_text("Your Expected Salary: {}".format(10000)) elif (age >= 21 and age <=26) and (year_exp >= 2 and year_exp <5): put_text("Your Expected Salary: {}".format(40000)) elif (age >= 27) and (year_exp >=5): put_text("Your Expected Salary: {}".format(90000)) else: put_text("Not in scoped rules!")
async def get_result(cmd): """ params: cmd - 要执行的命令 """ if re.search('[;&|<>$]', cmd): popup('检测到非法字符', content="请检查命令中是否包含;&|等特殊字符, 并刷新重试") return popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) while True: buff = popen.stdout.readline() if buff: put_text(buff) elif popen.poll() is not None: break
def bmi(): height = input("Input your height(cm):", type=FLOAT) weight = input("Input your weight(kg):", type=FLOAT) BMI = weight / (height / 100)**2 top_status = [ (16, "Severely underweight"), (18.5, "Underweight"), (25, "Normal"), (30, "Overweight"), (35, "Moderately obese"), (float("inf"), "Severely obese"), ] for top, status in top_status: if BMI <= top: put_text("Your BMI: %.1f. Category: %s" % (BMI, status)) break
def __init__(self): env = os.getenv('FLYOS') if env is None: env = '.' self.__path = os.path.abspath(env + '/virtualmachine') if not os.path.exists(os.path.abspath(self.__path + "/vms")): os.mkdir(os.path.abspath(self.__path + "/vms")) set_env(title="FlyOS Virtual Machine", auto_scroll_bottom=True) put_html("<h1>FlyOS WEB Virtual Machine</h1>") put_text("FlyOS Virtual Machine By:XingYuJie", sep=" ") popup( "欢迎使用FlyOS FlyOS Virtual Machine!", "欢迎使用FlyOS Virtual Machine。" "开始创建您的虚拟机吧!" "程序由MicroTech Projects -- FlyOS强力驱动", ) pwd = pywebio.input.input("输入flyos密码:") if termux_auth.auth(pwd): self.__run() else: popup("密码错误,请刷新页面重试")
def _show() -> None: put_scope('header', [ put_html(Icon.ALAS).style("--header-icon--"), put_text("Alas").style("--header-text--"), put_scope('header_status'), put_scope('header_title'), ]) put_scope('contents', [ put_scope('aside'), put_scope('menu'), put_scope('content'), ])
def demo(): inputs = input_group("All Input Types", [ input("Integer Input", type=NUMBER, name="integer_in"), textarea("This is a text area", type=TEXT, name='text_area'), select("This is a selection", options=[('Software Engineer', 1), ('Data Analyst', 2), ('Artist', 3)], name='selection'), checkbox("This is a checkbox", options=[('Software Engineer', 1), ('Data Analyst', 2), ('Artist', 3)], name='check_box'), radio("This is a radio selection", options=[('Software Engineer', 1), ('Data Analyst', 2), ('Artist', 3)], name='radio_selection') ]) put_text( "Integer: {}\nTextArea: {}\nSelection: {}\nCheckBox: {}\nRadioButton: {}" .format(inputs['integer_in'], inputs['text_area'], inputs['selection'], inputs['check_box'], inputs['radio_selection']))