Wednesday, 24 June 2015

Dart POW - ( Package Of The Week) #9 : dart_feed

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

dart_feed is a simple RSS 2.0 feed reader library. It is pretty easy to use - here's my simplified version of one of the examples.

library DartFeed.example;

import 'dart:io';
import 'package:dart_feed/dart_feed.dart';

List webFeeds = [
  "http://divingintodart.blogspot.com/feeds/posts/default?alt=rss"
];

main() {
  
  FeedParser parser = new FeedParser();
  parser.stream.listen(printFeed);
  
  for (var feed in webFeeds) {
    parser.fromUri(Uri.parse(feed));
  }
}

void printFeed(Feed feed) {
  print(feed.title);
  for (var item in feed.items) {
    stdout.write("\t ${item.title}");
    if (item.title == "") print(item.description);
    else print("");
  }
}

Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)