Skip to content

Instantly share code, notes, and snippets.

@sriedel
Created June 29, 2012 07:18
Show Gist options
  • Save sriedel/3016439 to your computer and use it in GitHub Desktop.
Save sriedel/3016439 to your computer and use it in GitHub Desktop.
copy opt-out-urls from xml feed
file = File.readlines( "20120628T111327_1" )
hash = {}
pairs = file.grep( /extid|opt_out_url/ ).
map { |e| e.gsub( /<.*?>/, '' ) }.
map(&:strip)
pairs.shift
pairs.each_slice( 2 ) { |e| hash[e[0].to_i] = e[1] }
hash.delete(0)
UserApplication.find( hash.keys ).
select { |e| e.opt_out_url.blank? }.
each do |e|
e.opt_out_url = hash[e.id]
e.save( :validate => false )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment