第四十二期-利用Python直接生成全仓库文件的永久直链

发布于 2020-08-05  383 次阅读


上代码

 

import re
import requests
findName = re.compile(r'"name":"(.*?)"')
findSha256 = re.compile(r'"digest":"(.*?)"')
def getURL(baseurl):
    req = requests.get(baseurl)
    print("已获取到仓库地址")
    html = req.content.decode("utf-8")
    html0 = html.replace("[","")
    html1 = html0.replace("]","")
    html2 = html1.replace("{","")
    html3 = html2.replace("}","")
    name = re.findall(findName,html3)
    sha256 = re.findall(findSha256,html3)
    print("已找到信息")
    with open("仓库内文件链接.txt","w+") as txt:
        print("save...")
        j = 1
        k = 1
        for names in name:
            txt.write("%d、%s"%(j,names))
            j += 1
            txt.write('\n')
        txt.write('\n')
        for sha256s in sha256:
            txt.write("%d.%s" % (k, 'http://drcd.leeskyler.top:3000/api/download?repository='))
            k += 1
            txt.write(number)
            txt.write('&digest=')
            txt.write(sha256s)
            txt.write('\n')
    txt.close()
    print("下载完成")
tip = "©Copyright 2020 Harry & Skyler All Rights Reserved\n-------Based On Python 3.8.5--------\n\n本程序只可获取属性为公开的仓库内的文件名和包含sha256值的永久直链\n输入仓库地址后回车将会有txt文件生成在脚本所在根目录\n如果您曾在相同路径下运行过本脚本,此脚本将会覆盖原先生成的txt,请注意备份\n请在下方输入仓库地址,不要带:/\n\n\n"
number = input(tip)
baseurl = "http://drcd.leeskyler.top:3000/api/items?repository=" + str(number)
getURL(baseurl)

py文件下载
Download


Skyler & Harry 's Notes