Aggregating RSS items in Java

I am trying to create a polling service in Java that checks for updates from an RSS feed.

When new elements are detected, it should send only new elements in the system.

Is there an API that does this, or will I need to do comparison checks?

At the moment, my oprolist is simply returning what he is currently seeing, causing duplicates in my system.

+3
source share
3 answers

Similar to what you need, available at Informa

"The Poller module is designed to provide convenient services for background polling of channel changes."

http://informa.sourceforge.net/poller.html

0
source

Sun RSS Utilities, . RSS- , , .

( ):

http://java.sun.com/developer/technicalArticles/javaserverpages/rss_utilities/

, GUID GUID .

// Create an RSS Parser
RssParser parser = RssParserFactory.createDefault();

// Parse the feed
Rss rss = parser.parse( new URL( YOUR_FEED ) );

// Get the channel
Channel channel = rss.getChannel();

// Get the items
Collection<Item> items = channel.getItems();

// Loop for each item
for ( Item item : items )
{
  // Get the GUID
  Guid guid = item.getGuid();

  // Loop for each of the previously seen GUIDs and compare
}
+1

, java... , . , RSS , RSS . API Informa, http://informa.sourceforge.net/

public class Read_UpdateRSS implements de.nava.informa.utils.poller.PollerObserverIF {

public static void main(String[] args) {

try {

        File in = new File("/home/RSSFeed/rssfeed.xml");

        ChannelBuilder build = new ChannelBuilder();

        Channel channel = (Channel) FeedParser.parse(build,in);
        System.out.println("Description:" + channel.getDescription());
        System.out.println("Title:" + channel.getTitle());

        // Magic of polling starts here. polling is done every 10 minutes

        Poller poll = new Poller();
        PollerObserverIF observer = new Read_UpdateRSS();
        poll.addObserver(observer);
        poll.registerChannel(channel, 10 * 60 * 1000);

        for(Object x: channel.getItems()){

            Item anItem = (Item) x;
            System.out.println(anItem.getTitle() + "-");
            System.out.println(anItem.getDescription());
    }

    } catch (Exception e) {

    }
}

@Override
public void channelChanged(ChannelIF arg0) {}

@Override
public void channelErrored(ChannelIF arg0, Exception arg1) {}

@Override
public void itemFound(ItemIF item, ChannelIF channel) {

    System.out.println("new item found");
    channel.addItem(item);
}

@Override
public void pollFinished(ChannelIF channel) {
    System.out.println("Finished polling with " +  channel.getItems().size() + " items in the channel");

}

@Override
public void pollStarted(ChannelIF channel) {
    System.out.println("Started polling with " + channel.getItems().size() + " items in the channel");

}

}

0

Source: https://habr.com/ru/post/1733341/


All Articles