Exemplo n.º 1
0
 def backup_existed_file():
     if os.path.exists(DirName):  # 备份一下本地已经爬到的文件
         Avalon.info("备份本地已经爬到的文件")
         try:
             os.rename(
                 DirName, DirName + "-" + time.strftime(
                     "%Y%m%d-%Hh", time.localtime(int(time.time()))))
         except OSError:
             Avalon.info("备份文件已经存在")
Exemplo n.º 2
0
 def delete_old_files():
     Avalon.info("删除3天以前的备份...")
     Dirname_backuped = DirName + "-" + time.strftime(
         "%Y%m%d-%Hh", time.localtime(int(time.time()) - 86400 * 3))
     if os.path.exists(Dirname_backuped):
         Avalon.warning("检测到3天前的备份,删除ing...")
         shutil.rmtree(Dirname_backuped)
         Avalon.info("删除完毕")
     else:
         Avalon.warning("未发现3天前的备份,跳过")
Exemplo n.º 3
0
 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("消息发送错误")
Exemplo n.º 4
0
 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("源目录不存在,跳过")
Exemplo n.º 5
0
def customized_tools():
    #  以下--删除3天以前的备份
    Tools.delete_old_files()
    #  以下--复制文件到网站目录
    if copy_to_website == 1:
        Avalon.info("准备复制文件到网站目录----")
        Tools.copydir_overwrite(_from_path="./%s" % DirName,
                                _to_path=website_dir + DirName)
    elif copy_to_website == 0:
        Avalon.info("跳过 复制文件到网站目录")
    #  以下--向server酱推送消息
    if not sckey == "":
        Avalon.info("尝试向Server酱推送消息……")
        Tools.send_wxmsg(_sckey=sckey,
                         _title="贴吧备份(全部楼层)",
                         _context="今日份的备份已完成...\n\n一切顺利..Maybe..\n\n帖子id:%d" %
                         pid)
    else:
        Avalon.warning("SCKEY为空,跳过微信推送")
Exemplo n.º 6
0
def add_css():
    with open("main.css", "wb+") as code:
        code.write(css.encode())
        Avalon.info("CSS文件已释放")
Exemplo n.º 7
0
                GetComment(fnum, pid, floor["id"])
        if (lastfid == fid):
            break
        # print(fid,lastfid)
        lastfid = fid


while (1):
    try:
        if (Avalon.ask("批量模式?", False)):
            PreSet = True
            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:
Exemplo n.º 8
0
def Init(pid, overwrite):
    global FileHandle, Progress, AudioCount, VideoCount, ImageCount, Pool, IsDownload, DirName, IsCreate, OutputHTML, FFmpeg, OutPutFileName, DirName_New
    IsDownload = set()
    IsCreate = set()
    AudioCount = VideoCount = ImageCount = 0
    if (os.path.isdir(DirName)):
        Avalon.warning("\"%s\"已存在" % DirName)
        if (overwrite == 1):
            Avalon.warning("跳过%d" % pid)
        elif (overwrite == 2):
            Avalon.warning("默认覆盖\"%s\"" % DirName)
        elif (overwrite == 3):
            if (len(DirName) > 30):
                DirName_New = DirName[:-11]
            else:
                DirName_New = DirName
            if (Server):
                Avalon.info("已将已存在文件夹备份至" +
                            (datetime.datetime.now().strftime('%m-%d')) + "/" +
                            DirName_New + " " +
                            (datetime.datetime.now() -
                             datetime.timedelta(hours=12)).strftime('%H-%M'))
                shutil.move(DirName,
                            (datetime.datetime.now().strftime('%m-%d')) + "/" +
                            DirName_New + " " +
                            (datetime.datetime.now() -
                             datetime.timedelta(hours=12)).strftime('%H-%M'))
            if not (Server):
                Avalon.info("已将已存在文件夹备份至" +
                            (datetime.datetime.now().strftime('%m-%d')) + "/" +
                            DirName_New + " " +
                            datetime.datetime.now().strftime('%H-%M'))
                shutil.move(DirName,
                            (datetime.datetime.now().strftime('%m-%d')) + "/" +
                            DirName_New + " " +
                            datetime.datetime.now().strftime('%H-%M'))
            os.makedirs(DirName)
        elif (not Avalon.ask("是否覆盖?", False)):
            raise UserCancelled("...")
    elif (os.path.exists(DirName)):
        raise OSError("存在同名文件")
    else:
        os.makedirs(DirName)
    if (OutputHTML):
        FileHandle = open("%s/%s.html" % (DirName, OutPutFileName),
                          "w+",
                          encoding="utf-8")
        Write(Html_Header)
        Write("<title>%s</title>\n" % (title_name))
        if (exe_mode):
            if (not_work_path):
                shutil.copy("main.css", DirName + "/")
            elif not (not_work_path):
                shutil.copy(exe_path + "/main.css", DirName + "/")
        else:
            shutil.copy(sys.path[0] + "/main.css", DirName + "/")
    else:
        FileHandle = open("%s/%s.md" % (DirName, OutPutFileName),
                          "w+",
                          encoding="utf-8")
    try:
        subprocess.Popen("ffmpeg",stdout=subprocess.DEVNULL,\
            stderr=subprocess.DEVNULL).wait()
        FFmpeg = 1
    except FileNotFoundError:
        Avalon.warning("未找到ffmpeg,语音将不会被转为mp3")
        FFmpeg = 0
    Pool = DownloadPool(DirName + "/", "file")
    Progress = tqdm(unit="floor")
Exemplo n.º 9
0
DirName_New = ""
OverWriteMode = 0
PreList = list()
PreDirList = list()
CopyDir = ""
Copy = False
Delay = False
Delay_time = ""
Delay_times = ""

exe_mode = False
if ('.exe' in sys.argv[0]):
    add_css()
    exe_mode = True
    Avalon.info("正在以exe模式运行")

if (Server):
    pid = 6684644957  #6477171863#4016579360
    #6477171863
    #帖子链接/id
    lz = False
    #是否只看楼主
    comment = True
    #是否包含评论
    DirName = "ppp"
    #输出文件夹路径,为空则默认为(\"吧名\\标题\)
    OutPutFileName = "index"
    #输出文件名,方便网站部署,为空则默认为帖子pid
    OutputHTML = True
    #是否输出html,否则输出markdown
Exemplo n.º 10
0
    if not sckey == "":
        Avalon.info("尝试向Server酱推送消息……")
        Tools.send_wxmsg(_sckey=sckey,
                         _title="贴吧备份(全部楼层)",
                         _context="今日份的备份已完成...\n\n一切顺利..Maybe..\n\n帖子id:%d" %
                         pid)
    else:
        Avalon.warning("SCKEY为空,跳过微信推送")


if __name__ == '__main__':
    os.chdir(sys.path[0])  # 切换至脚本文件所在目录
    DirName_flag = 0
    for pid in pids:
        try:
            Avalon.info("当前时间: " + time.strftime(
                "%Y-%m-%d %H:%M:%S", time.localtime(int(time.time()))))
            Avalon.info("帖子id: %d" % pid)
            title = GetTitle(pid)
            title["forum"] = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "_",
                                    title["forum"])
            title["post"] = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "_", title["post"])
            #  lz = Avalon.ask("只看楼主?", False)
            Avalon.info("只看楼主: " + str(lz))
            #  comment = (0 if lz else Avalon.ask("包括评论?", True))
            Avalon.info("包括评论: " + str(comment))
            #  DirName = Avalon.gets("文件夹名(空则表示使用\"吧名-标题\"):")
            DirName = DirNames[DirName_flag]
            Avalon.info("目录名: " + DirName)
            Tools.backup_existed_file()  # 备份已爬取的文件
            #  OutputHTML = Avalon.ask("输出HTML(否则表示输出Makrdown)?:", True)
            Avalon.info("输出为Html: " + str(OutputHTML))