utils: ipfs changes

This commit is contained in:
SouthFox 2022-06-14 11:09:30 +08:00
parent b72826dbd3
commit 6f14782528

View file

@ -104,8 +104,11 @@ def backupImg():
result = re.findall('!\[(.*?)\]\((.*?)\)', mdText) result = re.findall('!\[(.*?)\]\((.*?)\)', mdText)
for i in range(len(result)): for i in range(len(result)):
img_quote = result[i][0] #img_quote = result[i][0]
img_url = result[i][1] img_url = result[i][1]
if 'ipfs' in img_url:
urlname = img_url.split(u"/")
img_url = str(urlname[-1])
nowImgList.append(img_url) nowImgList.append(img_url)
downLoadList = list(set(nowImgList).difference((set(imgJson["img"])))) downLoadList = list(set(nowImgList).difference((set(imgJson["img"]))))
@ -127,15 +130,13 @@ def backupImg():
def downloadImg(imgList): def downloadImg(imgList):
ipfs_gateWay = ['https://cf-ipfs.com/ipfs/', 'https://ipfs.io/ipfs/', 'https://dweb.link/ipfs/']
for img_url in imgList: for img_url in imgList:
# img name spell img_name = img_url
urlname = img_url.split(u"/")
img_name = str(urlname[-1])
if img_url == "": if img_url == "":
continue continue
# download img # download img
ipfs_gateWay = ['https://cf-ipfs.com/ipfs/', 'https://ipfs.io/ipfs/', 'https://dweb.link/ipfs/'] if 'https' not in img_url:
if 'ipfs' in img_url:
img_url = random.choice(ipfs_gateWay) + img_name img_url = random.choice(ipfs_gateWay) + img_name
response = requests.get(img_url) response = requests.get(img_url)