0

Have do i display and extract data from a feed url? And I only of the interest to import/display those there have the catogory_id of 10

This is the feed url:

http://www.euroads.dk/system/api.php?username=x&password=x&function=campaign_feed&eatrackid=13614&version=5

The format on the feed is:

 campaignid;;advertid;;title;;startdate;;enddate;;amountleft;;price;;percent;;campaigntype;;targetage;;targetsex;;category;;category_id;;cpc;;advert_type;;advert_title;;bannerwidth;;bannerheight;;textlink_length;;textlink_text;;advert_url;;advert_image;;advert_code;;campaign_teaser;;reward/cashback;;SEM;;SEM restrictions

Here is a sample code of the feed:

campaignid;;advertid;;title;;startdate;;enddate;;amountleft;;price;;percent;;campaigntype;;
targetage;;targetsex;;category;;category_id;;cpc;;advert_type;;advert_title;;bannerwidth;;bannerheight;;textlink_length;;textlink_text;;advert_url;;advert_image;;advert_code;;campaign_teaser;;reward/cashback;;SEM;;SEM restrictions <br/> <br/> 2603;;377553;;MP3 afspiller;;2010-07-21;;2011-12-31;;-1;;67,00;;;;Lead kampagne;;Over 18;;Alle;;Elektronik;Musik, film & spil;;7,13;;0,97;;Banner;;;;930;;180;;0;;;;http://tracking.euroads.dk/system<br/> <br/> /tracking.php?sid=1&cpid=2603&adid=377553&acid=4123&eatrackid=13614;;http://banner.euroads.dk/banner/1/2603/banner_21153.gif;;;;http://banner.euroads.dk/banner/1/2603/teaserbanner_1617.gif;;Allowed;;
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Rails beginner
  • 14,321
  • 35
  • 137
  • 257
  • Those samples are not valid RSS/Atom feeds. Are they some other (unknown) type of feed that is not a news feed? RDF/RSS/Atom are all XML-based and can be easily parsed using Nokogiri. – the Tin Man Feb 16 '11 at 23:32
  • It is a API feed to automatic import campaigns. (Unknown feed) And it is really large. There is a PHP example of have to extract data from the feed. I will ask them if I may share it here. – Rails beginner Feb 16 '11 at 23:52

1 Answers1

0

The data format looks like a variation on CSV, if ';;' is used as a column separator. Based on that:

require 'csv'
CSV.parse(data, :col_sep => ';;') do |csv|
  # do something with each record
end

data will be the content you receive.

Inside the loop, csv will be an array containing each record's fields. The first time through the loop will be the headers and subsequent times through csv will be the data records.

Sometimes you'll see ';;;;', which means there's an empty field; For instance, field;;;;field which would convert to ['field',nil,'field'] in csv. You'll need to figure out what you want to do with nil records. I'd suggest you'll probably want to map those to empty strings ('').

the Tin Man
  • 158,662
  • 42
  • 215
  • 303