Skip to content

Commit

Permalink
notify fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
aelkiss committed Apr 30, 2024
1 parent 9f2f21e commit 19aa9ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
41 changes: 20 additions & 21 deletions lib/datasets/notify.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
require 'net/smtp'
require 'datasets/dedupe_delete_log'
require "net/smtp"
require "datasets/dedupe_delete_log"

DATASET_EMAILS = [
['ht_text_pd','dataset-pd','pd'],
['ht_text_pd_open_access','dataset-pd-oa','pd_open'],
['ht_text_pd_world','dataset-pd-world','pd_world'],
['ht_text_pd_world_open_access','dataset-pd-world-oa','pd_world_open']
["ht_text_pd", "dataset-pd", "pd"],
["ht_text_pd_open_access", "dataset-pd-oa", "pd_open"],
["ht_text_pd_world", "dataset-pd-world", "pd_world"],
["ht_text_pd_world_open_access", "dataset-pd-world-oa", "pd_world_open"]
]

SUPPORT_EMAIL = "[email protected]"

module Datasets
class Notify
def initialize(files,
dry_run:,
smtp_host:)
dry_run:,
smtp_host:)
@dry_run = dry_run
@smtp_host = smtp_host
@delete_logs = Datasets::DedupeDeleteLog.new(files)
Expand All @@ -23,16 +23,16 @@ def initialize(files,
def notify
deletes = delete_logs.compile_results

DATASET_EMAILS.each do |subset_full_name,email,subset_short_name|
email(subset_full_name,"#{email}@hathitrust.org",deletes[subset_short_name])
DATASET_EMAILS.each do |subset_full_name, email, subset_short_name|
email(subset_full_name, "#{email}@hathitrust.org", deletes[subset_short_name])
end
end

private

attr_reader :dry_run, :delete_logs, :smtp_host, :files

def email_header(set_name,recipient)
def email_header(set_name, recipient)
<<~DOC
From: HathiTrust <#{SUPPORT_EMAIL}>
To: #{recipient}
Expand All @@ -41,7 +41,7 @@ def email_header(set_name,recipient)
Dear HathiTrust dataset recipient,
This email is to notify you that volumes in the HathiTrust \"#{set_name}\" dataset, of which you have downloaded all or a subset of files, no longer meet the criteria for inclusion in the dataset, and you no longer are allowed to use them in your research.
This email is to notify you that volumes in the HathiTrust "#{set_name}" dataset, of which you have downloaded all or a subset of files, no longer meet the criteria for inclusion in the dataset, and you no longer are allowed to use them in your research.
Please review the data you have synced from HathiTrust to check whether you have the volumes listed below. If so, delete all copies you retain of these volumes in accordance with our terms of use. Alternatively, you may delete your copy of the dataset and re-sync to the updated dataset.
Expand All @@ -55,31 +55,30 @@ def email_header(set_name,recipient)
DOC
end

def email(set_name,recipient,data)
return unless data && data.count
def email(set_name, recipient, data)
return unless data&.count

message = email_header(set_name,recipient)
message = email_header(set_name, recipient)

data.each do |item|
message+="#{item}\n"
message += "#{item}\n"
end
message+="===END ID LIST===\n"
message += "===END ID LIST===\n"

puts "sending message with #{data.count} deletes to #{recipient}"
send_or_preview(message,recipient)
send_or_preview(message, recipient)
end

def send_or_preview(message,recipient)
def send_or_preview(message, recipient)
if dry_run
puts "To: #{SUPPORT_EMAIL}, #{recipient}"
puts
puts message
else
Net::SMTP.start(smtp_host) do |smtp|
Net::SMTP.start(smtp_host) do |smtp|
smtp.send_message message, SUPPORT_EMAIL, recipient
end
end
end

end
end
2 changes: 1 addition & 1 deletion spec/notify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Datasets
f.puts("pd\ttest.id1", "pd\ttest.id2")
f.close

notifier = Notify.new([f.path], dry_run: true, smtp_host: 'default.invalid')
notifier = Notify.new([f.path], dry_run: true, smtp_host: "default.invalid")
expect { notifier.notify }.to output(/Delete notification.*test\.id1.*test\.id2/m).to_stdout
end
end
Expand Down

0 comments on commit 19aa9ec

Please sign in to comment.