There is a LOT of garbage in this code. Notes to myself, print statements to debug, etc. But this is the current incarnation of the secret santa code I'm using. The old XML/Outlook version in C sharp was better, but I ran into email issues with Office moving online and switching employers and ending up on a Mac. Now I just generate .txt files.
2022 updates should include getting rid of the separate checks for exclusions and telling it to check for anyone in the full exclusion list so I can make it ragged.
Here....target == who[1] or target == who[2] or target == who[0]
And there's a lot of unnecessary iterative garbage to make sure it can brute force it's way to a list when it gets toward the end where it might dead end itself. But to be honest, that doesn't take 100 iterations, it's over in like four. Anyway...I think I can boil this down to a dozen lines of code, so maybe I'll do that next year. Personally, I'm just glad I was able to find it again after moving machines twice in 2.5 years.
#0 fix the code >>
#0a put the guts of the retry in a function that can error out with an error message
#0b and let the error message run a global retry
# load >> run >> each person >> one person fails >> clear and run
#1 import from a settings file (don't need a UI although the last one had one)
#2 which means we need to write to a settings file
# name, spouse, last year (use the format year(last)file.txt as the default
# use JSON instead of XML this time), ah....need an email address!
#3 put it in a bucket (file) in S3, put the code in a python lambda
#4 autoemail - lambda send email with ses: https://aws.amazon.com/
#2020 list...this needs to generate from input/output
#e.g. that last value should be a read from last year's file
listWho = [("Scott","Jen","Jackie")]
listWho = listWho + [("Eryn","Scott","Jen")]
listWho = listWho + [("Oliver","Jackie","Andrew")]
listWho = listWho + [("Jen","Scott","Ceri")]
listWho = listWho + [("Andrew","Jackie","Jen")]
listWho = listWho + [("Jackie","Andrew","John")]
listWho = listWho + [("Allison","Ceri","Andrew")]
listWho = listWho + [("Ceri","Allison","Ellen")]
listWho = listWho + [("John","Ellen","Scott")]
listWho = listWho + [("Ellen","John","Allison")]
def LoopLoop(listWho):
targetExclusion = []
for who in listWho:
#print (len(listWho))
#print(who)
print(" ")
print(" ")
print("Owner: " + who[0])
myRand = random.randint(0,len(listWho)-
#print("random: " + str(myRand))
target = listWho[myRand][1]
#print("target: " + target)
myIter = 0
#could put all this in a function and call for success or failure
#eg while false...
#target can't be used already
while target == who[1] or target == who[2] or target == who[0] or target in targetExclusion:
target = listWho[random.randint(0,len(
print("temp target: " + target)
myIter = myIter + 1
#print(myIter)
if myIter >=100:
print("I FAILED")
return False;
#break #kill it and we will start over
targetExclusion = targetExclusion + [target]
print(targetExclusion)
print("target: " + target)
f= open(str(datetime.now().year) + "_" + who[0] + ".txt","w+")
f.write("YOUR SECRET SANTA RECIPIENT IS: " + target)
f.close()
#do it again
#actually, turn this into the loop
return True; #ah, this is where I"m failing, I have to get to len to return true
print(listWho)
mybool = False
print(mybool)
while mybool == False:
print(mybool)
mybool = LoopLoop(listWho)
print ("Mybool = ")
print (mybool)
print ("end of script")
No comments:
Post a Comment