Last active
April 14, 2023 23:58
-
-
Save cbaclig/a24d40d2bfa74f348df826dfafda08e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "csv" | |
desc "Create Tags in Bulk" | |
task :bulk_create_feed_tags, [:filename] => :environment do |t, args| | |
filename = args[:filename] | |
CSV.read(filename, headers: true).each do |row| | |
puts "Processing placement: #{row["Placement Name"]}..." | |
feed_name = row["Spaceback Feed Name"] | |
feed = Feed.where(name: feed_name).first | |
raise "no feed found" unless feed.present? | |
feed_tag = FeedTag.new( | |
name: row["Placement Name"], | |
partner_id: "dv360", | |
feed: feed, | |
) | |
raise "Assuming only 1 Creative on Feed!" unless feed.feed_creatives.length == 1 | |
feed_tag_tracker_attributes = feed_tag.feed.feed_creatives.map do |fc| | |
{ | |
feed_creative_id: fc.id, | |
click_tracker: row["Landing Page"], | |
impression_tracker: "#{row["IAS Pixel"]}\n#{row["Dynata Pixel/Tag"]}", | |
uses_click_tracker_as_primary_destination_url: true, | |
} | |
end | |
feed_tag.feed_tag_trackers.build(feed_tag_tracker_attributes) | |
feed_tag.valid? | |
# Delete errors on DCM related associations | |
feed_tag.errors.delete(:dcm_placement_id) | |
feed_tag.errors.delete(:dcm_ad_id) | |
raise "invalid FeedTag #{row["Placement Name"]}: #{feed_tag.errors.full_messages.to_sentence}" unless feed_tag.errors.empty? | |
puts "done!" | |
# DCMService.new.create_feed_tag(feed, feed_tag).tap do |dcm_feed_tag| | |
# feed_tag.assign_attributes( | |
# dcm_placement_id: dcm_feed_tag[:placement_id], | |
# dcm_ad_id: dcm_feed_tag[:ad_id], | |
# ) | |
# feed_tag.save! | |
# end | |
# TODO: Also need to call UpdateFeedCreativeStatusJob after this? | |
# TODO: call UpdateCreativeJob too | |
break | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment