From 9fc37f1048fbd182e00eea89b71ec644f7d9df56 Mon Sep 17 00:00:00 2001 From: imgyh <1974355683@qq.com> Date: Tue, 28 Mar 2023 17:19:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(tiktok):=20=E9=87=8D=E8=AF=95=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=90=8E=E8=BF=94=E5=9B=9E=E5=B7=B2=E7=BB=8F=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E7=9A=84=E6=95=B0=E6=8D=AE,=20=E8=80=8C?= =?UTF-8?q?=E4=B8=8D=E6=98=AF=E6=8A=9B=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TikTok.py | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/TikTok.py b/TikTok.py index 89cf807..0b9a7a3 100644 --- a/TikTok.py +++ b/TikTok.py @@ -165,8 +165,10 @@ class TikTok(object): except Exception as e: end = time.time() # 结束时间 if end - start > self.timeout: - raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") - print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") + # raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + return {} + # print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") # 清空self.awemeDict self.result.clearDict(self.result.awemeDict) @@ -229,15 +231,18 @@ class TikTok(object): except Exception as e: end = time.time() # 结束时间 if end - start > self.timeout: - raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") - print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") + # raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + return awemeList + # print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") for aweme in datadict["aweme_list"]: # 获取 aweme_id aweme_id = aweme["aweme_id"] # 深拷贝 dict 不然list里面全是同样的数据 datanew, dataraw = self.getAwemeInfo(aweme_id) - awemeList.append(copy.deepcopy(datanew)) + if datanew is not None and datanew != {}: + awemeList.append(copy.deepcopy(datanew)) if numflag: number-=1 if number==0: @@ -278,9 +283,11 @@ class TikTok(object): except Exception as e: end = time.time() # 结束时间 if end - start > self.timeout: - raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") - if option: - print("[ 错误 ]:接口未返回数据, 正在重新请求!\r") + # raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + return {} + # if option: + # print("[ 错误 ]:接口未返回数据, 正在重新请求!\r") # 清空字典 self.result.clearDict(self.result.liveDict) @@ -389,15 +396,18 @@ class TikTok(object): except Exception as e: end = time.time() # 结束时间 if end - start > self.timeout: - raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") - print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") + # raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + return awemeList + # print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") for aweme in datadict["aweme_list"]: # 获取 aweme_id aweme_id = aweme["aweme_id"] # 深拷贝 dict 不然list里面全是同样的数据 datanew, dataraw = self.getAwemeInfo(aweme_id) - awemeList.append(copy.deepcopy(datanew)) + if datanew is not None and datanew != {}: + awemeList.append(copy.deepcopy(datanew)) if numflag: number -= 1 if number == 0: @@ -453,8 +463,10 @@ class TikTok(object): except Exception as e: end = time.time() # 结束时间 if end - start > self.timeout: - raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") - print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") + # raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + return mixIdNameDict + # print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") for mix in datadict["mix_infos"]: mixIdNameDict[mix["mix_id"]] = mix["mix_name"] @@ -513,15 +525,18 @@ class TikTok(object): except Exception as e: end = time.time() # 结束时间 if end - start > self.timeout: - raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") - print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") + # raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据") + return awemeList + # print("[ 警告 ]:接口未返回数据, 正在重新请求!\r") for aweme in datadict["aweme_list"]: # 获取 aweme_id aweme_id = aweme["aweme_id"] # 深拷贝 dict 不然list里面全是同样的数据 datanew, dataraw = self.getAwemeInfo(aweme_id) - awemeList.append(copy.deepcopy(datanew)) + if datanew is not None and datanew != {}: + awemeList.append(copy.deepcopy(datanew)) if numflag: number -= 1 if number == 0: