You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
  1. #!/usr/bin/env ruby
  2. require 'awesome_print'
  3. require 'action_mailer'
  4. require 'pry-byebug'
  5. I18n.load_path = Dir['locale/*.yml']
  6. I18n.available_locales = %i[fr]
  7. I18n.default_locale = :fr
  8. I18n.enforce_available_locales = false
  9. ActionMailer::Base.raise_delivery_errors = true
  10. ActionMailer::Base.delivery_method = :smtp
  11. ActionMailer::Base.smtp_settings = {
  12. address: 'localhost',
  13. port: 1025,
  14. openssl_verify_mode: 'none'
  15. }
  16. ActionMailer::Base.view_paths = File.dirname(__FILE__)
  17. class Mailer < ActionMailer::Base
  18. def notify(to, events)
  19. puts "Notify #{to} with #{events.size} events"
  20. @events = events
  21. mail from: 'conferences@passageenseine.fr',
  22. # to: to,
  23. to: %W[aeris@imirhil.fr],
  24. subject: '[PSES] Conférence retenue'
  25. end
  26. end
  27. TYPES = {
  28. talk: 'Conférence',
  29. workshop: 'Atelier'
  30. }.freeze
  31. planning = YAML.load(File.read 'config/2019.yml').deep_symbolize_keys
  32. events = []
  33. planning.each do |date, ess|
  34. ess.each do |_, es|
  35. es.each do |e|
  36. email = e[:email]
  37. next unless email
  38. events << {
  39. email: email,
  40. type: TYPES[e[:type].to_sym],
  41. title: e[:title],
  42. date: date,
  43. from: e[:from],
  44. to: e[:to]
  45. }
  46. end
  47. end
  48. end
  49. events = events.group_by { |e| e[:email] }.to_h
  50. events.each do |to, events|
  51. Mailer.notify(to, events).deliver
  52. break
  53. end