電子メール受信者のファイルが与えられた場合、これによりマッチをランダム化し、それぞれの試合に電子メールを送信します。アプリケーションは、誰も自分自身を取得しないことを保証しますが、他のすべての組み合わせは有効と見なされます。このプログラムは、明示的にそうするように指示されない限り、オペレーターへの一致を示さないことに注意してください。
課題は、誰も持っていないまで繰り返しシャッフルされます。これは永遠に続く可能性がありますが、アプリに1人の参加者のみを提供しない限り、そうではありません。それはあなたがクリスマスに孤独になることを意味しますが、あなたの家は、1枚のカードの2つのデッキを異なる注文にシャッフルしようとするために、あなたのコンピュータが際限なく回転することによって温められます。
割り当てが確立されたら、メールが送信され、作業が完了します。キャロルの練習をして、もう一度Eggnogのレシピをテストすることに戻りましょう。
古代の放棄されたライブラリでメールをフォーマットしているという事実を除いて、このアプリはかなり非常に過剰に構築されています。 8回のシャッフルと約2秒の後、100Kレコードで有効なマッチセットを生成することができました。ただし、100kの電子メールを送信するには明らかに時間がかかります!
go get
(logrus、urfave.cli、gophermail)go build
secret-santa
実行可能ファイルをコンパイルします./secret-santa
を実行しますsecret-santa
参加者リストをJSONファイルから入力します。各参加者は、 name
とaddress
パラメーターを持つ配列のメンバーになります。これにより、 data/people.json
がデフォルトですが、 --source-file
パラメーターで好きなパスを使用できます。詳細については、例をご覧ください。
また、テンプレートファイルを作成して、電子メール本体をカスタマイズする必要があります。ファイルは{{.From}}
と{{.To}}
をサポートします。これは、参加者JSONファイルから引用された名前です。これにより、 data/email.template
がデフォルトですが、 --template-file
パラメーターで好きなパスを使用できます。詳細については、例をご覧ください。
NAME:
secret-santa - Secret Santa Emailer!
USAGE:
secret-santa [global options] command [command options] [arguments...]
VERSION:
0.0.1
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--from-name value Display name for sender (default: "Secret Santa Robotic Elf")
--from-address value Email address to send from (required unless dry run)
--from-password value Password for the from-address (e.g. gmail password)
--smtp-host value Host to send to (default: "smtp.gmail.com")
--smtp-port value Port to send to (default: 587)
--source-file value JSON file containing an array of name/address objects (default: "data/people.json")
--template-file value Text file containing a template used for the email body (default: "data/email.template")
--subject value Email subject (default: "Shhhh! It's your Secret Santa assignment")
--show-matches Print the pairings out when sending
--dry-run Do not send. Implies --show-matches
--help, -h show help
--version, -v print the version
$ ./secret-santa --dry-run --source-file data/example.json
INFO[0000] Shuffling...
INFO[0000] Shuffling...
INFO[0000] Shuffling...
INFO[0000] Shuffling...
INFO[0000] Shuffling...
INFO[0000] match from="Dee Dee" to=Tommy
INFO[0000] match from=Ringo to="Dee Dee"
INFO[0000] match from=George to=Paul
INFO[0000] match from=Joey to=George
INFO[0000] match from=Marky to=Ringo
INFO[0000] match from=Paul to=Marky
INFO[0000] match from=John to=Joey
INFO[0000] match from=Tommy to=John
$ ./secret-santa --from-address "[email protected]" --from-password "your_pass" --source-file data/people.json
INFO[0000] Shuffling...
INFO[0000] Shuffling...
INFO[0001] sent
INFO[0002] sent
INFO[0002] sent
INFO[0003] sent
INFO[0004] sent
INFO[0005] sent
INFO[0006] sent
INFO[0007] sent
INFO[0008] sent
INFO[0009] sent