main.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/python
  2. ####! /usr/bin/python
  3. # This script will read a database of name / email address
  4. # Once read, the script will assign each name with another name
  5. # The script will ensure each name is drawn by only one other name
  6. # Each name cannot draw their own name
  7. # Once assigned, the script will email each user with their assigned name
  8. # Future enhancements
  9. # User website to log in to be reminded which person they have - PROB cannot do for privacy
  10. # Monitor an email address for incoming emails... if received, send a reminder emaiil to the sender which name they have been assigned
  11. ## TODO
  12. # Read XML list
  13. # ramdomly assign names to names
  14. import random
  15. import json
  16. from datetime import datetime
  17. def getsantalist(listname):
  18. resultslist = []
  19. random.shuffle(listname)
  20. for i in range(len(listname)):
  21. resultsdict = {}
  22. santa = listname[i]
  23. if i <= len(listname)-2:
  24. secret = listname[i+1]
  25. else:
  26. secret = listname[0]
  27. resultsdict["santa"] = santa
  28. resultsdict["secret"] = secret
  29. resultslist.append(resultsdict)
  30. # print(santa, secret)
  31. return resultslist
  32. with open("users.json") as json_file:
  33. file = json.load(json_file)
  34. list_santas = []
  35. for user in file["user"]:
  36. list_santas.append(user['name'])
  37. santalist = getsantalist(list_santas)
  38. print(santalist)
  39. print(datetime.now().strftime("%Y"), "Secret Santa")
  40. print("-----------------")
  41. for pair in santalist:
  42. print(pair["santa"], pair["secret"])