import gradio as gr import datetime import pytz introduce = """
要求每日签到,七天未签到者踢出组织
""" def get_log() -> list[str]: with open("log.txt", "r", encoding="utf8") as f: return f.read() def set_timezone(): now = datetime.datetime.now() beijing = pytz.timezone("Asia/Shanghai") return now.astimezone(beijing) NICKNAME = [ ['ZYeon',], ['gutenmorgen', 'gtmg'], ['liusu',], ['graci', 'gracilaria'] ] def last_signin(name) -> str: for nn in NICKNAME: if name in nn: for line in get_log(): nameInLog = line[3 : line.find(',')] if nameInLog in nn: return line[line.find('时间:')+3 : -1] return '' def add_log(name:str) -> None: with open("log.txt", "a", encoding="utf8") as f: f.write("昵称: " + (name+',').ljust(10) + "时间: " + str(set_timezone()) + "\n") def signin(name): last_time = last_signin(name) add_log(name) return name + "已签到。\n上一次签到时间:" + last_signin with gr.Blocks() as system: with gr.Row(): gr.HTML(introduce) with gr.Row(): with gr.Column(): name=gr.Textbox(label="name") sign_button=gr.Button("签到") with gr.Column(): output=gr.Textbox(label="output",interactive=False) get_button=gr.Button("查看日志") get_button.click(get_log,inputs=[],outputs=[output]) sign_button.click(signin,inputs=[name],outputs=[output]) system.launch()