-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
22 deletions.
There are no files selected for viewing
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
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) | ||
|
@@ -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} | ||
|
@@ -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. | ||
|
@@ -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 |
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