def main(self): global ACCOUNTS # todo 存档文件格式 # 解析存档文件 # account_id account_list = robot.read_save_data(self.save_data_path, 0, ["", ]) ACCOUNTS = account_list.keys() # 循环下载每个id main_thread_count = threading.activeCount() for account_id in sorted(account_list.keys()): # 检查正在运行的线程数 while threading.activeCount() >= self.thread_count + main_thread_count: if robot.is_process_end() == 0: time.sleep(10) else: break # 提前结束 if robot.is_process_end() > 0: break # 开始下载 thread = Download(account_list[account_id], self.thread_lock) thread.start() time.sleep(1) # 检查除主线程外的其他所有线程是不是全部结束了 while threading.activeCount() > main_thread_count: time.sleep(10) # 未完成的数据保存 if len(ACCOUNTS) > 0: new_save_data_file = open(NEW_SAVE_DATA_PATH, "a") for account_id in ACCOUNTS: new_save_data_file.write("\t".join(account_list[account_id]) + "\n") new_save_data_file.close() # todo 是否需要下载图片或视频 # 删除临时文件夹 tool.remove_dir(IMAGE_TEMP_PATH) tool.remove_dir(VIDEO_TEMP_PATH) # 重新排序保存存档文件 robot.rewrite_save_file(NEW_SAVE_DATA_PATH, self.save_data_path) # todo 是否需要下载图片或视频 log.step("全部下载完毕,耗时%s秒,共计图片%s张,视频%s个" % (self.get_run_time(), TOTAL_IMAGE_COUNT, TOTAL_VIDEO_COUNT))
def main(self): global ACCOUNTS # 解析存档文件 # account_id image_count last_image_time video_count last_video_url (account_name) account_list = robot.read_save_data(self.save_data_path, 0, ["", "0", "0", "0", ""]) ACCOUNTS = account_list.keys() # 先访问下页面,产生cookies auto_redirect_visit("http://www.weibo.com/") time.sleep(2) # 循环下载每个id main_thread_count = threading.activeCount() for account_id in sorted(account_list.keys()): # 检查正在运行的线程数 while threading.activeCount() >= self.thread_count + main_thread_count: if robot.is_process_end() == 0: time.sleep(10) else: break # 提前结束 if robot.is_process_end() > 0: break # 开始下载 thread = Download(account_list[account_id], self.thread_lock) thread.start() time.sleep(1) # 检查除主线程外的其他所有线程是不是全部结束了 while threading.activeCount() > main_thread_count: time.sleep(10) # 未完成的数据保存 if len(ACCOUNTS) > 0: new_save_data_file = open(NEW_SAVE_DATA_PATH, "a") for account_id in ACCOUNTS: new_save_data_file.write("\t".join(account_list[account_id]) + "\n") new_save_data_file.close() # 删除临时文件夹 self.finish_task() # 重新排序保存存档文件 robot.rewrite_save_file(NEW_SAVE_DATA_PATH, self.save_data_path) log.step("全部下载完毕,耗时%s秒,共计图片%s张,视频%s个" % (self.get_run_time(), TOTAL_IMAGE_COUNT, TOTAL_VIDEO_COUNT))
def main(self): global ACCOUNTS # 解析存档文件 # account_name image_count video_count last_created_time account_list = robot.read_save_data(self.save_data_path, 0, ["", "0", "0", "0"]) ACCOUNTS = account_list.keys() if not set_csrf_token(): log.error("token和session获取查找失败") tool.process_exit() # 循环下载每个id main_thread_count = threading.activeCount() for account_name in sorted(account_list.keys()): # 检查正在运行的线程数 while threading.activeCount() >= self.thread_count + main_thread_count: if robot.is_process_end() == 0: time.sleep(10) else: break # 提前结束 if robot.is_process_end() > 0: break # 开始下载 thread = Download(account_list[account_name], self.thread_lock) thread.start() time.sleep(1) # 检查除主线程外的其他所有线程是不是全部结束了 while threading.activeCount() > main_thread_count: time.sleep(10) # 未完成的数据保存 if len(ACCOUNTS) > 0: new_save_data_file = open(NEW_SAVE_DATA_PATH, "a") for account_name in ACCOUNTS: new_save_data_file.write("\t".join(account_list[account_name]) + "\n") new_save_data_file.close() # 删除临时文件夹 self.finish_task() # 重新排序保存存档文件 robot.rewrite_save_file(NEW_SAVE_DATA_PATH, self.save_data_path) log.step("全部下载完毕,耗时%s秒,共计图片%s张,视频%s个" % (self.get_run_time(), TOTAL_IMAGE_COUNT, TOTAL_VIDEO_COUNT))
def main(self): global ACCOUNTS # 检测登录状态 # 未登录时提示可能无法获取粉丝指定的作品 check_login() # 解析存档文件 # account_id last_rp_id account_list = robot.read_save_data(self.save_data_path, 0, ["", "0"]) ACCOUNTS = account_list.keys() # 循环下载每个id main_thread_count = threading.activeCount() for account_id in sorted(account_list.keys()): # 检查正在运行的线程数 while threading.activeCount() >= self.thread_count + main_thread_count: if robot.is_process_end() == 0: time.sleep(10) else: break # 提前结束 if robot.is_process_end() > 0: break # 开始下载 thread = Download(account_list[account_id], self.thread_lock) thread.start() time.sleep(1) # 检查除主线程外的其他所有线程是不是全部结束了 while threading.activeCount() > main_thread_count: time.sleep(10) # 未完成的数据保存 if len(ACCOUNTS) > 0: new_save_data_file = open(NEW_SAVE_DATA_PATH, "a") for account_id in ACCOUNTS: new_save_data_file.write("\t".join(account_list[account_id]) + "\n") new_save_data_file.close() # 重新排序保存存档文件 robot.rewrite_save_file(NEW_SAVE_DATA_PATH, self.save_data_path) log.step("全部下载完毕,耗时%s秒,共计图片%s张" % (self.get_run_time(), TOTAL_IMAGE_COUNT))