Python Newsaggregator-停止重复的rss条目

问题描述

简而言之,我创建了一个新闻聚合器,该新闻聚合器从给定的Feed获取最新的三个上载内容。该脚本可以正常工作,但是我一直在尝试对其进行编辑,以使它不会输出与上次运行脚本时输出的相同的文章

import Feedparser

class News:

    def __init__(self,url):
        self.url = url
        self.newsFeed  = Feedparser.parse(self.url)

    def get_news(self):
        print("##########################################")
        try:
            print("Publication: ",self.newsFeed.Feed.title)
        except: 
            print("Publication has no title")
            
        print("##########################################")
        for i in range(3):
            print("-------------------------------------------------------------",end="")
            print("-------------------------------------------------------------------")
            entry = self.newsFeed.entries[i]
            with open("/home/ramel/Projects/news_aggregator/read.txt","a+") as done:
                if entry.link in done.read():
                    continue
                else:
                    done.write(entry.link + "\n")

            print("Title: ",entry.title)
            
            try:
                print(entry.published)
            except:
                print("Date UnkNown")

            print(entry.link)

如您所见,我已经尝试制作另一个txt文件,其中包含每个链接的网址。然后,我将在输出之前检查文件,以查看链接是否已在文件中。如果是这样,那么我们可以继续进行下一个迭代/文章。任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)