Browse Source

Initial Commit

mike 1 tuần trước cách đây
commit
be3fa67705
4 tập tin đã thay đổi với 107 bổ sung0 xóa
  1. 2 0
      .gitignore
  2. 23 0
      Users.xml
  3. 57 0
      main.py
  4. 25 0
      users.json

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+./idea/
+*.swp

+ 23 - 0
Users.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<users>
+    <user>
+        <name>Mike</name>
+        <email>M_Stagl@hotmail.com</email>
+    </user>
+    <user>
+        <name>Amy</name>
+        <email>M_Stagl2@hotmail.com</email>
+    </user>
+    <user>
+        <name>Jacob</name>
+        <email>M_Stagl2@hotmail.com</email>
+    </user>
+    <user>
+        <name>James</name>
+        <email>M_Stagl2@hotmail.com</email>
+    </user>
+    <user>
+        <name>Kate</name>
+        <email>M_Stagl2@hotmail.com</email>
+    </user>
+</users>

+ 57 - 0
main.py

@@ -0,0 +1,57 @@
+#! /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"])

+ 25 - 0
users.json

@@ -0,0 +1,25 @@
+{
+  "user": [
+    {
+      "name": "Mike",
+      "email": "M_Stagl@hotmail.com"
+    },
+    {
+      "name": "Amy",
+      "email": "amy@sffive.com"
+    },
+    {
+      "name": "Jacob",
+      "email": "jacob@sffive.com"
+    },
+    {
+      "name": "James",
+      "email": "james@sffive.com"
+    },
+    {
+      "name": "Kate",
+      "email": "kate@sffive.com"
+    }
+  ]
+}
+