Skip to content

Commit

Permalink
Updated Leander:
Browse files Browse the repository at this point in the history
* added metware channel (yes, I need to put this in a config file)
* use linked list (hopefully solving fixing showing new feed items)
  • Loading branch information
egonw committed May 20, 2009
1 parent 288aa95 commit 1d63ef5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
25 changes: 17 additions & 8 deletions src/com/github/egonw/rednael/Feed.java
Expand Up @@ -16,20 +16,18 @@
package com.github.egonw.rednael;

import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.LinkedList;

public class Feed {

private String label;
private URL url;
private List<String> queue;
private LinkedList<String> queue;

public Feed(String label, URL url) {
this.label = label;
this.url = url;
queue = new ArrayList<String>();
queue = new LinkedList<String>();
}

public String getLabel() {
Expand All @@ -45,11 +43,22 @@ public boolean contains(String link) {
}

public void add(String link) {
queue.add(link);
System.out.println("Added link: " + link);
queue.addFirst(link);
// feeds that are smaller than what they normally should be, e.g.
// because they just started, will mess up... assume feeds have 50
// items, then the when only 8 out of 10 are given (== partial feed)
// , will not mess up the same. Fails for partial feeds with more than
// 50 items as default, but that should be rare (tm)
if (queue.size() > 50)
queue.removeLast();
}

public void reverse() {
Collections.reverse(queue);
public void addInitial(String link) {
System.out.println("Added initial link: " + link);
// the first time a feed is read, the first item must be at the top
// of the list, so next is added always as last
queue.addLast(link);
}

}
Expand Down
17 changes: 12 additions & 5 deletions src/com/github/egonw/rednael/LeanderBot.java
Expand Up @@ -45,7 +45,7 @@ public class LeanderBot extends PircBot {
private FeedFetcher fetcher;

public LeanderBot() throws NickAlreadyInUseException, IOException, IrcException {
this.setName("rednael");
this.setName("hadhadhadhadhadhadhadhadhad");
this.setVerbose(true);
this.connect("irc.freenode.net");
this.channels = new ArrayList<Channel>();
Expand All @@ -61,6 +61,9 @@ public LeanderBot() throws NickAlreadyInUseException, IOException, IrcException
"http://cdk.git.sourceforge.net/git/gitweb.cgi?p=cdk;a=rss;h=refs/heads/"
+ branch
));
cdk.addFeed("CDK Twitter", new URL(
"http://search.twitter.com/search.atom?q=%23cdk"
));
addChannel(cdk);

Channel bioclipse = new Channel("#bioclipse");
Expand All @@ -75,6 +78,12 @@ public LeanderBot() throws NickAlreadyInUseException, IOException, IrcException
));
addChannel(bioclipse);

Channel metware = new Channel("#metware");
metware.addFeed("Metware Twitter", new URL(
"http://search.twitter.com/search.atom?q=%23metware"
));
addChannel(metware);

feedInfoCache = HashMapFeedInfoCache.getInstance();
fetcher = new HttpURLFeedFetcher(feedInfoCache);
}
Expand All @@ -94,11 +103,8 @@ private void boot() throws IllegalArgumentException, IOException, FeedException,
for (SyndEntry entry : entries) {
itemCount++;
String link = entry.getLink();
chFeed.add(link);
chFeed.addInitial(link);
}
// feeds have the latest entry first, but we want them at the last
// position
chFeed.reverse();
}
}
}
Expand All @@ -108,6 +114,7 @@ private void update() {
for (Feed chFeed : channel.getFeeds()) {
try {
SyndFeed feed = null;
System.out.println("Feed url: " + chFeed.getURL());
feed = fetcher.retrieveFeed(chFeed.getURL());
List<SyndEntry> entries = feed.getEntries();
for (SyndEntry entry : entries) {
Expand Down

0 comments on commit 1d63ef5

Please sign in to comment.