mirror of
https://github.com/imgyh/tiktok.git
synced 2025-04-24 17:03:58 +08:00
fix(tiktok): 重试失败后返回已经获取到的数据, 而不是抛异常
This commit is contained in:
parent
6b6978df49
commit
9fc37f1048
41
TikTok.py
41
TikTok.py
@ -165,8 +165,10 @@ class TikTok(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
end = time.time() # 结束时间
|
end = time.time() # 结束时间
|
||||||
if end - start > self.timeout:
|
if end - start > self.timeout:
|
||||||
raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
# raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
|
return {}
|
||||||
|
# print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
||||||
|
|
||||||
# 清空self.awemeDict
|
# 清空self.awemeDict
|
||||||
self.result.clearDict(self.result.awemeDict)
|
self.result.clearDict(self.result.awemeDict)
|
||||||
@ -229,14 +231,17 @@ class TikTok(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
end = time.time() # 结束时间
|
end = time.time() # 结束时间
|
||||||
if end - start > self.timeout:
|
if end - start > self.timeout:
|
||||||
raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
# raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
|
return awemeList
|
||||||
|
# print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
||||||
|
|
||||||
for aweme in datadict["aweme_list"]:
|
for aweme in datadict["aweme_list"]:
|
||||||
# 获取 aweme_id
|
# 获取 aweme_id
|
||||||
aweme_id = aweme["aweme_id"]
|
aweme_id = aweme["aweme_id"]
|
||||||
# 深拷贝 dict 不然list里面全是同样的数据
|
# 深拷贝 dict 不然list里面全是同样的数据
|
||||||
datanew, dataraw = self.getAwemeInfo(aweme_id)
|
datanew, dataraw = self.getAwemeInfo(aweme_id)
|
||||||
|
if datanew is not None and datanew != {}:
|
||||||
awemeList.append(copy.deepcopy(datanew))
|
awemeList.append(copy.deepcopy(datanew))
|
||||||
if numflag:
|
if numflag:
|
||||||
number-=1
|
number-=1
|
||||||
@ -278,9 +283,11 @@ class TikTok(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
end = time.time() # 结束时间
|
end = time.time() # 结束时间
|
||||||
if end - start > self.timeout:
|
if end - start > self.timeout:
|
||||||
raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
# raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
if option:
|
print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
print("[ 错误 ]:接口未返回数据, 正在重新请求!\r")
|
return {}
|
||||||
|
# if option:
|
||||||
|
# print("[ 错误 ]:接口未返回数据, 正在重新请求!\r")
|
||||||
|
|
||||||
# 清空字典
|
# 清空字典
|
||||||
self.result.clearDict(self.result.liveDict)
|
self.result.clearDict(self.result.liveDict)
|
||||||
@ -389,14 +396,17 @@ class TikTok(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
end = time.time() # 结束时间
|
end = time.time() # 结束时间
|
||||||
if end - start > self.timeout:
|
if end - start > self.timeout:
|
||||||
raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
# raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
|
return awemeList
|
||||||
|
# print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
||||||
|
|
||||||
for aweme in datadict["aweme_list"]:
|
for aweme in datadict["aweme_list"]:
|
||||||
# 获取 aweme_id
|
# 获取 aweme_id
|
||||||
aweme_id = aweme["aweme_id"]
|
aweme_id = aweme["aweme_id"]
|
||||||
# 深拷贝 dict 不然list里面全是同样的数据
|
# 深拷贝 dict 不然list里面全是同样的数据
|
||||||
datanew, dataraw = self.getAwemeInfo(aweme_id)
|
datanew, dataraw = self.getAwemeInfo(aweme_id)
|
||||||
|
if datanew is not None and datanew != {}:
|
||||||
awemeList.append(copy.deepcopy(datanew))
|
awemeList.append(copy.deepcopy(datanew))
|
||||||
if numflag:
|
if numflag:
|
||||||
number -= 1
|
number -= 1
|
||||||
@ -453,8 +463,10 @@ class TikTok(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
end = time.time() # 结束时间
|
end = time.time() # 结束时间
|
||||||
if end - start > self.timeout:
|
if end - start > self.timeout:
|
||||||
raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
# raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
|
return mixIdNameDict
|
||||||
|
# print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
||||||
|
|
||||||
for mix in datadict["mix_infos"]:
|
for mix in datadict["mix_infos"]:
|
||||||
mixIdNameDict[mix["mix_id"]] = mix["mix_name"]
|
mixIdNameDict[mix["mix_id"]] = mix["mix_name"]
|
||||||
@ -513,14 +525,17 @@ class TikTok(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
end = time.time() # 结束时间
|
end = time.time() # 结束时间
|
||||||
if end - start > self.timeout:
|
if end - start > self.timeout:
|
||||||
raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
# raise RuntimeError("重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
print("[ 提示 ]:重复请求该接口" + str(self.timeout) + "s, 仍然未获取到数据")
|
||||||
|
return awemeList
|
||||||
|
# print("[ 警告 ]:接口未返回数据, 正在重新请求!\r")
|
||||||
|
|
||||||
for aweme in datadict["aweme_list"]:
|
for aweme in datadict["aweme_list"]:
|
||||||
# 获取 aweme_id
|
# 获取 aweme_id
|
||||||
aweme_id = aweme["aweme_id"]
|
aweme_id = aweme["aweme_id"]
|
||||||
# 深拷贝 dict 不然list里面全是同样的数据
|
# 深拷贝 dict 不然list里面全是同样的数据
|
||||||
datanew, dataraw = self.getAwemeInfo(aweme_id)
|
datanew, dataraw = self.getAwemeInfo(aweme_id)
|
||||||
|
if datanew is not None and datanew != {}:
|
||||||
awemeList.append(copy.deepcopy(datanew))
|
awemeList.append(copy.deepcopy(datanew))
|
||||||
if numflag:
|
if numflag:
|
||||||
number -= 1
|
number -= 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user