def save_file(data: str, filename: str) -> None: """ 文件保存 """ init_path(filename) with pathlib.Path(filename).open("wb") as f: f.write(data)
def save_worker(data: dict, filename: str = "res.pkl"): """ 会话保存 """ with check_times(f"Saved {filename}"): init_path(filename) with pathlib.Path(filename).open("wb") as f: pickle.dump((data), f)
def create_xlsx(data: dict, columns: list, filename: str = "res.xlsx"): with check_times(f"Created {filename}"): xlsx = pandas.DataFrame(data) xlsx.rename(columns={_: __ for _, __ in enumerate(columns)}, inplace=True) init_path(filename) writer = pandas.ExcelWriter(filename, options={"strings_to_urls": False}) xlsx.to_excel(writer, "data") writer.save()
MM_SEND_FILE_STATUS_SENDING = 1 MM_SEND_FILE_STATUS_SUCCESS = 2 MM_SEND_FILE_STATUS_FAIL = 3 MM_SEND_FILE_STATUS_CANCEL = 4 MM_EMOTICON_WEB = "_web" # ------------------------------------------------------------------------- API_checktimeout = 25.04 API_checknums = 5 from webot.common import init_path YOUR_NAME = "张三" API_conf_path = init_path("extra/") API_log_path = init_path(f"{API_conf_path}/log/") # 聊天记录 markdown API_static_path = init_path(f"{API_conf_path}/static/") # 生成的配置文件及实时记录 API_analysis_path = init_path(f"{API_conf_path}/analysis/") # 各类分析结果及导出数据 API_media_path = init_path(f"{API_conf_path}/meidas/") # 媒体数据 API_media_icon_path = init_path(f"{API_media_path}/icons/") # 头像 API_meida_voice_path = init_path(f"{API_media_path}/voices/") # 语音 API_meida_image_path = init_path(f"{API_media_path}/images/") # 图片 API_meida_emoji_path = init_path(f"{API_media_path}/emoji/") # 表情 API_meida_video_path = init_path(f"{API_media_path}/videos/") # 视频 API_hotreload_file = f"{API_static_path}/wxbot.pkl" API_qrcode_name = f"{API_static_path}/qrcode.jpg"
def create_json(data: dict, filename: str = "res.json"): with check_times(f"Saved {filename}"): init_path(filename) with pathlib.Path(filename).open("w") as f: f.write(json.dumps(data, ensure_ascii=False, indent=4))