Skip to content

Instantly share code, notes, and snippets.

@flsafe flsafe/refresh.rb
Created Aug 29, 2012

Embed
What would you like to do?
refresh ads
pdfs=[
"864546-01.pdf",
"869017-01.pdf",
"869017-01.pdf",
"867131-01.pdf",
"867131-01.pdf",
"865896-01.pdf",
"865896-01.pdf",
"863510-01.pdf",
"863510-01.pdf",
"864049-01.pdf",
"864049-01.pdf",
"864049-01.pdf",
"866812-01.pdf",
"869020-01.pdf",
"864339-01.pdf",
"864339-01.pdf",
"868066-01.pdf",
"865582-01.pdf",
"873716-01.pdf",
"868111-01.pdf",
"865274-01.pdf",
"865274-01.pdf",
"868143-01.pdf",
"868143-01.pdf",
"865613-01.pdf",
"864372-01.pdf",
"864372-01.pdf",
"863585-01.pdf",
"863585-01.pdf",
"867236-02.pdf",
"867236-02.pdf",
"869357-01.pdf",
"870748-01.pdf",
"868082-01.pdf",
"859763-01.pdf",
"863797-01.pdf",
"873394-01.pdf",
"869035-01.pdf",
"866880-01.pdf",
"867262-01.pdf"]
pe = Publisher.first(:name => 'The Press-Enterprise')
raise "No publisher PE" if pe.nil?
businesses = Ad.all(:pdf_file_name=>pdfs).map(&:business).uniq
raise "No businesses with pdf_file_names found" if businesses.empty?
raise "Unexpected businesses" unless businesses.all?{|b|b.publisher == pe}
businesses.each do |b|
ad = b.ads.last
ad.start_date = Date.today
ad.end_date = Date.today+7.days
unless ad.save
raise "Could not refresh last ad for business #{b.name}: #{ad.errors.full_messages}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.