尝试记录下载文件,而不是重新下载它们

时间:2017-12-13 17:44:16

标签: python-3.x

日志文件正确写入,但我似乎无法查看链接是否在文件中,因此不会再次下载

cats_path = r"G:\Cat"
logs_write = open(r"G:\Cat\.logs.txt", "a")
logs_read = open(r"G:\Cat\.logs.txt", "r")

read = logs_read.readlines()


subreddit = reddit.subreddit("cats") #SUBREDDIT
hot_python = subreddit.hot(limit=10)
print(read)
for submission in hot_python:
if not submission.stickied:
    link = submission.url + r"\n"
    if link not in read:    #LOOK IF LINK IN LOG FILE
        print(submission.url + " THIS IS THE submission.url")
        logs_write.write(submission.url + "\n") #ADD LOG FILE
        if submission.url[8:14] == "gfycat":
            gfycat = r"http://giant.gfycat.com/" + submission.url[19:] + ".mp4"
            wget.download(gfycat, cats_path)  #DOWNLOAD
        elif submission.url[-4:] == "gifv":
            mp4 = submission.url[:-5] + ".mp4"
            wget.download(mp4, cats_path)  #DOWNLOAD
        else:
            wget.download(submission.url, cats_path) #DOWNLOAD
    else:
        print(submission.url + "is already here")

0 个答案:

没有答案