可自定義的秘密聖誕老人名稱列表生成器
該腳本的目的是:
為每個買家分配秘密聖誕老人活動的禮物接收器列表。用戶可以指定每個買家應該購買的禮物數量,並且該程序將確保沒有買家兩次繪製相同名稱。
將電子郵件發送給所有秘密的聖誕老人參與者,告訴他們誰來購買禮物。
畫一棵聖誕樹,並將其包括在電子郵件中以進行節日。聖誕樹是以下字符的字符串:[,],=,〜。
電子郵件的外觀示例:
git clone https://github.com/tylerlum/DrawNames.git
cd DrawNames
pip install -e .
python run_draw.py --help
usage: run_draw.py [--name_to_email_dict NAME_TO_EMAIL_DICT]
[--name_to_nickname_dict NAME_TO_NICKNAME_DICT]
[--n_recipients_per_buyer N_RECIPIENTS_PER_BUYER]
[--email_subject_line EMAIL_SUBJECT_LINE]
[--email_used_to_send EMAIL_USED_TO_SEND] [-h]
optional arguments:
--name_to_email_dict NAME_TO_EMAIL_DICT
(Dict[str, str], default={'Tyler':
'[email protected]', 'OtherTyler':
'[email protected]'}) Tyler
--name_to_nickname_dict NAME_TO_NICKNAME_DICT
(Dict[str, str], default={'Tyler': 'Tygertron',
'OtherTyler': 'SwoleDude'}) Tyler
--n_recipients_per_buyer N_RECIPIENTS_PER_BUYER
(int, default=1)
--email_subject_line EMAIL_SUBJECT_LINE
(str, default=Sibling Secret Santa Draw 2023)
--email_used_to_send EMAIL_USED_TO_SEND
(Union[str, NoneType],
[email protected])
-h, --help show this help message and exit
筆記:
修改run_draw.py
中的默認參數要比直接使用命令行要容易得多。
大多數用戶需要將大多數參數修改為其特定用例
確保name_to_nickname_dict
和name_to_email_dict
具有相同的鍵
python run_draw.py
================================================================================
args = {'email_subject_line': 'Sibling Secret Santa Draw 2023',
'email_used_to_send': '[email protected]',
'n_recipients_per_buyer': 1,
'name_to_email_dict': {'OtherTyler': '[email protected]',
'Tyler': '[email protected]'},
'name_to_nickname_dict': {'OtherTyler': 'SwoleDude', 'Tyler': 'Tygertron'}}
================================================================================
--------------------------------------------------------------------------------
Reminder: to send emails, [email protected] must have app password set up.
If not set up, refer to https://support.google.com/mail/answer/185833?hl=en-GB or search for 'Sign in using app passwords'
--------------------------------------------------------------------------------
Enter the app password for [email protected]:
Thank you. Password was correct.
Names have been drawn!
Is this a valid assignment? True
Hi Tygertron! You will be buying a lovely present for: SwoleDude. :)
-Tyler Bot
NICKNAMES:
Tyler: Tygertron
OtherTyler: SwoleDude
[]
[~]
[~~]
[~~~]
[~~~~]
[~~~~~]
[~~~~~~]
[~~~~~~~]
[~~~~~~~~]
[~~~~~~~~~]
[~~~~~~~~~~]
[]
[]
[]
Email sent
Hi SwoleDude! You will be buying a lovely present for: Tygertron. :)
-Tyler Bot
NICKNAMES:
Tyler: Tygertron
OtherTyler: SwoleDude
[]
[~]
[~~]
[~~~]
[~~~~]
[~~~~~]
[~~~~~~]
[~~~~~~~]
[~~~~~~~~]
[~~~~~~~~~]
[~~~~~~~~~~]
[]
[]
[]
Email sent
Email sent
python run_draw.py
================================================================================
args = {'email_subject_line': 'Sibling Secret Santa Draw 2023',
'email_used_to_send': '[email protected]',
'n_recipients_per_buyer': 1,
'name_to_email_dict': {'OtherTyler': '[email protected]',
'Tyler': '[email protected]'},
'name_to_nickname_dict': {'OtherTyler': 'SwoleDude', 'Tyler': 'Tygertron'}}
================================================================================
--------------------------------------------------------------------------------
Reminder: to send emails, [email protected] must have app password set up.
If not set up, refer to https://support.google.com/mail/answer/185833?hl=en-GB or search for 'Sign in using app passwords'
--------------------------------------------------------------------------------
Enter the app password for [email protected]:
Traceback (most recent call last):
File "run_draw.py", line 115, in <module>
main()
File "run_draw.py", line 69, in main
email_sender = EmailSender(user=email_used_to_send, password=app_password)
File "<string>", line 5, in __init__
File "/home/tylerlum/github_repos/DrawNames/DrawNames/email_utils.py", line 38, in __post_init__
self.passwordcheck()
File "/home/tylerlum/github_repos/DrawNames/DrawNames/email_utils.py", line 33, in passwordcheck
server.login(self.user, self.password)
File "/home/tylerlum/miniconda3/envs/rlgpu/lib/python3.7/smtplib.py", line 735, in login
raise last_exception
File "/home/tylerlum/miniconda3/envs/rlgpu/lib/python3.7/smtplib.py", line 726, in login
initial_response_ok=initial_response_ok)
File "/home/tylerlum/miniconda3/envs/rlgpu/lib/python3.7/smtplib.py", line 647, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more atn5.7.8 https://support.google.com/mail/?p=BadCredentials ju17-20020a170903429100b001c0a4146961sm4804704plb.19 - gsmtp')