vendredi 2 décembre 2022

Hidden Friend in Python

I'm trying to create a hidden friend for my company. In this logic, they will fill out a google forms form and, at the end of the week, I will download it to my computer as a csv file. the data collected are: Full name, email address and desired gift. The idea is to automate the draw and each member will receive a secret friend in their email, with an email address to present them with a virtual gift.

At the stage I'm at, I'm putting together the logic of the draw, but I'm not managing to develop. Because it's not making sense of the draw. One person is drawing two and it should only be one at a time.

import glob
import random
import csv
from itertools import permutations, combinations_with_replacement, combinations


all_list = []
for glob in glob.glob("random_friend/csv/*"):
    file1 = open(glob, "r+")
    reader = csv.reader(file1, delimiter=',')
    for i in reader:
        all_list.append(i)
    all_list.pop(0)

perm = permutations(all_list)

gift = random.choice(['chocolat', 'Squeeze', 'fridge magnet', 'popcorn door cushion kit', 'cocktail shaker kit', 'Suspense book'])

print(gift)

for i in perm:
    name_one = i[1][1]
    name_two = i[2][1]
    mail_one = i[1][2]
    mail_two = i[2][2]

    print(f"""{name_one} took {name_two} and present with a {gift} and send it by e-mail to {mail_two}""")



Aucun commentaire:

Enregistrer un commentaire