How to display and import data from a feed url?
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 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 (''
).
精彩评论