Skip to content

Instantly share code, notes, and snippets.

@sbauch
Created August 28, 2012 20:14
Show Gist options
  • Save sbauch/3503626 to your computer and use it in GitHub Desktop.
Save sbauch/3503626 to your computer and use it in GitHub Desktop.
def self.seed_from_csv(uri)
CSV.read(uri).each do |row|
@post = Post.find_or_create_by_identifier(
:identifier => row[0],
:content => row[1],
:post_type => row[2],
:posted_at => row[5],
:post_impressions_unique => row[6],
:post_impressions_organic_unique => row[7],
:post_impressions_paid_unique => row[8],
:post_impressions_viral_unique => row[9],
:post_impressions => row[10],
:post_impressions_organic => row[11],
:post_impressions_paid => row[12],
:post_impressions_viral => row[13],
:post_engaged_users => row[14],
:post_storytellers => row[15],
:post_stories => row[16],
:post_storytellers_by_action_type => {'like' => row[17], 'share' => row[18], 'comment' => row[19], 'answer' => row[20], 'follow' => row[21]},
:post_stories_by_action_type => {'like' => row[22], 'share' => row[23], 'comment' => row[24], 'answer' => row[25], 'follow' => row[26]},
:post_consumptions_unique => row[27],
:post_consumptions => row[28],
:post_consumptions_by_type_unique => {'photo view' => row[29], 'other clicks' => row[30], 'link clicks' => row[31]},
:post_consumptions_by_type => {'other clicks' => row[32], 'photo view' => row[33], 'link clicks' => row[34]},
:post_negative_feedback_unique => row[35]
:post_negative_feedback => row[36],
:post_negative_feedback_by_type_unique => {'hide_all_clicks' => row[37], 'hide_clicks' => row[38], 'report_spam_clicks' => row[39], 'unlike_page_clicks' => row[40]},
:post_negative_feedback_by_type => {'hide_all_clicks' => row[41], 'hide_clicks' => row[42], 'report_spam_clicks' => row[43], 'unlike_page_clicks' => row[44]},
:post_impressions_fan => row[45],
:post_impressions_fan_unique => row[46],
:post_impressions_fan_paid => row[47],
:post_impressions_fan_paid_unique => row[48])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment