def send_wxmsg(_sckey, _title="标题", _context="正文"): url = "https://sc.ftqq.com/%s.send" % _sckey _context = _context + " \n\n" + time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime()) data = {"text": "%s" % _title, "desp": "%s" % _context} try: res = requests.post(url=url, data=data) msg_back = json.loads(res.text) if msg_back["errmsg"] == "success": Avalon.info("返回值:%s" % (msg_back["errmsg"])) else: Avalon.warning("返回值:%s" % (msg_back["errmsg"])) except Exception: Avalon.error("消息发送错误")
def copydir_overwrite(_from_path, _to_path): if os.path.exists(_from_path): if os.path.exists(_to_path): Avalon.warning("目标目录已存在,删除ing...") try: shutil.rmtree(_to_path) except Exception as err1: Avalon.error("删除目标文件失败,此次复制取消\n" + str(err1)) return 1 try: shutil.copytree(_from_path, _to_path) except Exception as err2: Avalon.error("复制失败!\n" + str(err2)) else: Avalon.info("复制成功") else: Avalon.warning("源目录不存在,跳过")
def ProcessContent(floor, data, in_comment): content = "" for s in data: try: if str(s["type"]) == "0": content += ProcessText(s["text"], in_comment) elif str(s["type"]) == "1": content += ProcessUrl(s["link"], s["text"]) elif str(s["type"]) == "2": content += ProcessEmotion(floor, s["text"], s["c"]) elif str(s["type"]) == "3": content += ProcessImg(s["origin_src"]) elif str(s["type"]) == "4": content += ProcessText(s["text"], in_comment) elif str(s["type"]) == "5": try: content += ProcessVideo(s["link"], s["src"]) except KeyError: content += ProcessQuoteVideo(s["text"]) elif str(s["type"]) == "9": content += ProcessText(s["text"], in_comment) elif str(s["type"]) == "10": content += ProcessAudio(s["voice_md5"]) elif str(s["type"]) == "11": content += ProcessImg(s["static"]) elif str(s["type"]) == "20": content += ProcessImg(s["src"]) else: Avalon.warning("floor %s: content data wrong: \n%s\n" % (floor, str(s)), front="\n") # raise UndifiedMsgType("content data wrong: \n%s\n"%str(s)) except KeyError: write_err_info() Avalon.error("KeyError! 建议修改源码中字典的Key\n" + traceback.format_exc(), front="\n") content += '\n<a>[Error] 这里似乎出错了...类型 KeyError</a>\n' except Exception: write_err_info() Avalon.error("发生异常:\n" + traceback.format_exc(), front="\n") content += '\n<a>[Error] 这里似乎出错了...</a>\n' else: return content
lz = Avalon.ask("只看楼主?", False) comment = (0 if lz else Avalon.ask("包括评论?", True)) OutputHTML = Avalon.ask("输出HTML(否则表示输出Makrdown)?:", True) overwrite = Avalon.ask("默认覆盖?", False) Avalon.info("选定:%s && %s评论 , 目录:\"吧名\\标题\"" % (("楼主" if lz else "全部"), ("全" if comment else "无"))) if (not Avalon.ask("确认无误?", True)): Avalon.warning("请重新输入") else: break else: PreSet = False break except KeyboardInterrupt: ForceStop() Avalon.error("Control-C,exiting", front="\n") exit(0) while (1): try: try: pid = int((Avalon.gets("请输入帖子链接或id(输入0退出):").split('/') )[-1].split('?')[0]) except Exception: Avalon.warning("未找到正确的id") continue if (pid == 0): exit(0) Avalon.info("id:%d" % pid) title = GetTitle(pid) title["forum"] = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "_", title["forum"])
Copy = False #是否对备份完成的帖子复制到部署文件夹,批量模式下不可用 CopyDir = "" #对备份完成的帖子复制到部署文件夹的路径 Auto_Clean = True #是否自动删除备份文件夹 Auto_Clean_time = 2 #自动删除几天前的备份文件夹 #TODO:自动删除 Work_path = "" #"C:\\Users\\28448\\Administrator\\Git\\TiebaBackup-complete\\td23" #设置工作目录,即备份文件储存目录 Avalon.info("正在以Server模式运行 " + str(datetime.datetime.now())) if (PreDirDirect): if (PreDirDirectMode != 0 and PreDirDirectMode != 1): Avalon.error("文件夹名直出模式错误!请更正!") exit() PreDirList = [] if (PreDirDirectMode == 0): for i in PreList: PreDirList.append(str(i)) elif (PreDirDirectMode == 1): for i in PreList: PreDirList.append("") PreList.append(0) PreDirList.append("0") else: Avalon.info("正在以交互模式运行 " + str(datetime.datetime.now())) if not (Server): try:
def write_err_info(): with open(save_path + "errors.txt", "a", encoding="utf-8") as f_err_info: f_err_info.writelines("https://tieba.baidu.com/p/" + str(pid) + "\n") Avalon.error(f"帖子 {pid} 可能出错, 帖子id已保存至 {save_path}errors.txt")