mirror of
https://github.com/Findus23/shuffle.git
synced 2024-09-19 14:43:45 +02:00
init
This commit is contained in:
commit
6aa81c2734
5 changed files with 67 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
config.py
|
||||||
|
.idea/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
7
config.sample.py
Normal file
7
config.sample.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
people = {
|
||||||
|
"Test1": "test1@example.com",
|
||||||
|
"Test2": "test2@example.com",
|
||||||
|
"Test3": "test3@example.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
sender = "Randomizer <script@example.com>"
|
25
derangement.py
Normal file
25
derangement.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from random import shuffle
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def is_derangement(original: List, shuffled: List) -> bool:
|
||||||
|
return not any([x == y for (x, y) in zip(original, shuffled)])
|
||||||
|
|
||||||
|
|
||||||
|
def get_derangement(people: List) -> List:
|
||||||
|
while True:
|
||||||
|
shuffled = people[:] # make a copy
|
||||||
|
shuffle(shuffled)
|
||||||
|
if is_derangement(people, shuffled):
|
||||||
|
return shuffled
|
||||||
|
|
||||||
|
|
||||||
|
def test():
|
||||||
|
a = [1, 2, 3, 4]
|
||||||
|
assert is_derangement(a, [2, 1, 4, 3])
|
||||||
|
assert not is_derangement(a, [1, 2, 4, 3])
|
||||||
|
assert not is_derangement(a, [1, 3, 4, 2])
|
||||||
|
assert is_derangement(a, get_derangement(a))
|
||||||
|
|
||||||
|
|
||||||
|
test()
|
17
mail.py
Normal file
17
mail.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import smtplib
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
|
from config import sender
|
||||||
|
|
||||||
|
s = smtplib.SMTP('localhost')
|
||||||
|
|
||||||
|
|
||||||
|
def notify(name: str, email: str, chosen_person: str) -> None:
|
||||||
|
to = f"{name} <{email}>"
|
||||||
|
|
||||||
|
msg = MIMEText(f"Hello {name},\n\nThe chosen person is {chosen_person}.")
|
||||||
|
msg['Subject'] = f"Result of shuffle for {name}"
|
||||||
|
msg['From'] = sender
|
||||||
|
msg['To'] = to
|
||||||
|
print(msg.as_string())
|
||||||
|
s.sendmail(sender, [to], msg.as_string())
|
14
main.py
Normal file
14
main.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from config import people
|
||||||
|
from derangement import get_derangement
|
||||||
|
from mail import notify
|
||||||
|
|
||||||
|
names = list(people.keys())
|
||||||
|
|
||||||
|
shuffled = get_derangement(names)
|
||||||
|
print(shuffled)
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
for name, email in people.items():
|
||||||
|
chosen_person = shuffled[i]
|
||||||
|
notify(name, email, chosen_person)
|
||||||
|
i += 1
|
Loading…
Reference in a new issue