def __init__(self, use_redis=False, debug=False, mood_begin=0, mood_num=-1, stop_time='-1', download_small_image=False, download_big_image=False, download_mood_detail=True, download_like_detail=True, download_like_names=True, recover=False, cookie_text=None, from_web=False, username='', nickname='', no_delete=True, pool_flag='127.0.0.1'): # 初始化下载项 self.mood_begin = mood_begin self.mood_num = mood_num self.recover = recover self.download_small_image = download_small_image self.download_big_image = download_big_image self.download_mood_detail = download_mood_detail self.download_like_detail = download_like_detail self.download_like_names = download_like_names self.thread_num = 5 self.thread_list = [] self.no_delete = no_delete if stop_time != '-1': self.stop_time = util.get_mktime(stop_time) else: self.stop_time = -1 self.begin_time = datetime.datetime.now() self.host = 'https://user.qzone.qq.com' self.h5_host = 'h5.qzone.qq.com' self.http_host = 'http://user.qzone.qq.com' self.use_redis = use_redis self.debug = debug self.cookie_text = cookie_text self.pool_flag = pool_flag if from_web: self.username = username self.nickname = nickname else: self.username, self.password, self.nickname = self.get_username_password( ) self.mood_host = self.http_host + '/' + self.username + '/mood/' # 在爬取好友动态时username会变为好友的QQ号,所以此处需要备份 self.raw_username = deepcopy(self.username) self.raw_nickname = deepcopy(self.nickname) self.headers = { 'host': 'user.qzone.qq.com', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.8', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:66.0) Gecko/20100101 Firefox/66.0', 'connection': 'keep-alive' } self.h5_headers = deepcopy(self.headers) self.h5_headers['host'] = self.h5_host if (use_redis): self.re = self.connect_redis() self.user_info = UserInfo(self.username).load() if self.user_info is None: self.user_info = UserInfo(self.username) self.user_info.QQ = self.username self.user_info.nickname = self.nickname self.image_thread_pool = ImageThreadPool(20) self.image_thread_pool2 = ThreadPoolExecutor(max_workers=20) self.init_file_name()
def __init__(self, use_redis=False, debug=False, mood_begin=0, mood_num=-1, stop_time='-1', download_small_image=False, download_big_image=False, download_mood_detail=True, download_like_detail=True, download_like_names=True, recover=False, cookie_text=None, from_web=False, username='', nickname='', no_delete=True, pool_flag='127.0.0.1', from_client=False): # 初始化下载项 self.mood_begin = mood_begin self.mood_num = mood_num self.recover = recover self.download_small_image = download_small_image self.download_big_image = download_big_image self.download_mood_detail = download_mood_detail self.download_like_detail = download_like_detail self.download_like_names = download_like_names # 控制线程数量,包括获取动态的线程数量和好友数据的线程数量,默认为10,这里表示两个子任务都开启10个线程 self.thread_num = 10 self.thread_list = [] self.from_client = from_client self.no_delete = no_delete if stop_time != '-1': self.stop_time = util.get_mktime(stop_time) else: self.stop_time = -1 self.begin_time = datetime.datetime.now() self.host = 'https://user.qzone.qq.com' self.h5_host = 'h5.qzone.qq.com' self.http_host = 'http://user.qzone.qq.com' self.use_redis = use_redis self.debug = debug self.cookie_text = cookie_text self.pool_flag = pool_flag self.from_web = from_web self.random_qr_name = str(random.random()) self.QR_CODE_PATH = BASE_PATH + '/src/web/static/image/qr' + self.random_qr_name self.headers = { 'host': 'user.qzone.qq.com', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.8', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:66.0) Gecko/20100101 Firefox/66.0', 'connection': 'keep-alive' } self.h5_headers = deepcopy(self.headers) self.h5_headers['host'] = self.h5_host if use_redis: self.re = self.connect_redis() if not from_web and not from_client: self.username, self.password, self.nickname = self.get_username_password( ) else: self.username = username self.nickname = nickname # 保存用户的二维码名称,传递给前端 if self.use_redis: self.re.hset(QR_CODE_MAP_KEY, self.username, self.random_qr_name) self.init_user_info() self.image_thread_pool = ImageThreadPool(20)
def __init__(self, use_redis=False, debug=False, mood_begin=0, mood_num=-1, stop_time='-1', download_small_image=False, download_big_image=False, download_mood_detail=True, download_like_detail=True, download_like_names=True, recover=False, cookie_text=None, from_web=False, username='', nickname='', no_delete=True, pool_flag='127.0.0.1'): # 初始化下载项 self.mood_begin = mood_begin self.mood_num = mood_num self.recover = recover self.download_small_image = download_small_image self.download_big_image = download_big_image self.download_mood_detail = download_mood_detail self.download_like_detail = download_like_detail self.download_like_names = download_like_names self.thread_num = 5 self.thread_list = [] self.no_delete = no_delete if stop_time != '-1': self.stop_time = util.get_mktime(stop_time) else: self.stop_time = -1 self.begin_time = datetime.datetime.now() self.host = 'https://user.qzone.qq.com' self.h5_host = 'h5.qzone.qq.com' self.http_host = 'http://user.qzone.qq.com' self.use_redis = use_redis self.debug = debug self.cookie_text = cookie_text self.pool_flag = pool_flag if from_web: self.username = username self.file_name_head = username self.nickname = nickname else: self.username, self.password, self.file_name_head, self.nick_name = self.get_username_password() self.mood_host = self.http_host + '/' + self.username + '/mood/' # 在爬取好友动态时username会变为好友的QQ号,所以此处需要备份 self.raw_username = deepcopy(self.username) self.headers = { 'host': 'user.qzone.qq.com', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'zh-CN,zh;q=0.8', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:66.0) Gecko/20100101 Firefox/66.0', 'connection': 'keep-alive' } self.h5_headers = deepcopy(self.headers) self.h5_headers['host'] = self.h5_host self.USER_BASE_DIR = BASE_DIR + self.username + '/' logging_dir = self.USER_BASE_DIR + 'log/' util.check_dir_exist(logging_dir) logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename=logging_dir + self.username + '.log', filemode='w+') if (use_redis): self.re = self.connect_redis() self.user_info = UserInfo(self.username).load() if self.user_info is None: self.user_info = UserInfo(self.username) self.user_info.QQ = self.username self.user_info.nickname = self.nickname