#! /usr/bin/python ####! /usr/bin/python # This script will read a database of name / email address # Once read, the script will assign each name with another name # The script will ensure each name is drawn by only one other name # Each name cannot draw their own name # Once assigned, the script will email each user with their assigned name # Future enhancements # User website to log in to be reminded which person they have - PROB cannot do for privacy # Monitor an email address for incoming emails... if received, send a reminder emaiil to the sender which name they have been assigned ## TODO # Read XML list # ramdomly assign names to names import random import json from datetime import datetime def getsantalist(listname): resultslist = [] random.shuffle(listname) for i in range(len(listname)): resultsdict = {} santa = listname[i] if i <= len(listname)-2: secret = listname[i+1] else: secret = listname[0] resultsdict["santa"] = santa resultsdict["secret"] = secret resultslist.append(resultsdict) # print(santa, secret) return resultslist with open("users.json") as json_file: file = json.load(json_file) list_santas = [] for user in file["user"]: list_santas.append(user['name']) santalist = getsantalist(list_santas) print(santalist) print(datetime.now().strftime("%Y"), "Secret Santa") print("-----------------") for pair in santalist: print(pair["santa"], pair["secret"])