Skip to content

Instantly share code, notes, and snippets.

@itszero
Created June 27, 2012 07:23

Revisions

  1. itszero created this gist Jun 27, 2012.
    5 changes: 5 additions & 0 deletions fetch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #!/bin/sh
    wget -O xml/top_albums.xml http://itunes.apple.com/tw/rss/topalbums/limit=300/explicit=true/xml
    wget -O xml/new_releases.xml http://itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/newreleases/sf=143470/limit=300/rss.xml
    wget -O xml/just_added.xml http://itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/justadded/sf=143470/limit=300/rss.xml
    wget -O xml/featured_albums.xml http://itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/featuredalbums/sf=143470/limit=300/rss.xml
    31 changes: 31 additions & 0 deletions parser.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    require 'bundler'
    require 'nokogiri'
    require 'uri'

    def parse_itms_feed(feed)
    d = Nokogiri(feed)
    d.css('feed entry').map { |entry|
    {
    :name => entry.css('name').text,
    :artist => entry.css('artist').text,
    :image => entry.css('image').max { |o| o['height'].to_i }.text,
    :price => entry.css('price').first['amount'].to_i,
    :id => entry.css('id').first['im:id'],
    :link => entry.css('link').first['href']
    }
    }
    end

    def parse_phobes_feed(feed)
    d = Nokogiri(feed)
    d.css('item').map { |entry|
    {
    :name => entry.css('itms|album').text,
    :artist => entry.css('itms|artist').text,
    :image => entry.css('itms|coverArt').max { |o| o['height'].to_i }.text,
    :price => entry.css('itms|albumPrice').text.gsub(/NT\$/,'').to_i,
    :id => File.basename(URI.parse(entry.css('link').text)).gsub(/id/,''),
    :link => entry.css('link').text
    }
    }
    end