Fetching/parsing iTunes RSS feeds with Nokogiri, storing the data in MongoDB, and displaying price sparks via Sinatra
Recently I’ve been tracking price drops in iTunes apps, so I thought I’d roll my own feed parser in Ruby and share the code. In this blog post I’ll demonstrate the following: MongoDB for document database storage, MongoID for the Ruby library, Curb for feed fetching, Nokogiri/Nori for XML parsing, Sinatra for a simple web server, and Google charts for a price spark image.
Installed MongoDB via Homebrew
Created a new project Gemfile, file: Gemfile
Created a MongoID config file, file: mongoid.yml
Created a mongo include file to define class structure for mongo objects, file: mongo.rb
Created a simple class to fetch, parse, and store the iTunes feed data, file: itunes_feed_fetcher.rb
Created a simple sinatra website with 2 urls (“/” and “/fetch”), file: sinatra.rb
I then started the sinatra app:
Browsing to http://localhost:4567/fetch fetches, parses, and stores the data in mongo. sample output:
Browsing to http://localhost:4567/ shows the feed items with a price spark image. As you can see I randomized the price spark data to make it more interesting.