Add weekly acrostics function
This commit is contained in:
parent
481a23da05
commit
bf4e96263a
1 changed files with 88 additions and 0 deletions
88
weekly.py
Normal file
88
weekly.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
import log
|
||||
import datetime
|
||||
|
||||
startdate = input("Enter the start date (MMDD): ")
|
||||
themonth = int(startdate[0:2])
|
||||
theday = int(startdate[2:4])
|
||||
|
||||
urls = []
|
||||
for event in log.log:
|
||||
if event["date"].year == datetime.datetime.today().year:
|
||||
if event["date"].month >= themonth:
|
||||
if event["date"].day >= theday:
|
||||
if "trade with " in event["event"]:
|
||||
try:
|
||||
if event["received"]:
|
||||
urls.append(event["url"])
|
||||
except:
|
||||
pass
|
||||
|
||||
candidates = []
|
||||
for event in log.log:
|
||||
if event["url"] in urls:
|
||||
try:
|
||||
for card in event["received"]:
|
||||
if "sig_" not in card:
|
||||
carddict = {}
|
||||
carddict["card"] = card
|
||||
carddict["player"] = event["event"][11:]
|
||||
carddict["url"] = event["url"]
|
||||
candidates.append(carddict)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
for card in event["lost"]:
|
||||
if "sig_" not in card:
|
||||
carddict = {}
|
||||
carddict["card"] = card
|
||||
carddict["player"] = event["event"][11:]
|
||||
carddict["url"] = event["url"]
|
||||
candidates.append(carddict)
|
||||
except:
|
||||
pass
|
||||
|
||||
maxcards = {}
|
||||
for card in candidates:
|
||||
theplayer = card["player"]
|
||||
if theplayer in maxcards:
|
||||
maxcards[theplayer] += 1
|
||||
else:
|
||||
maxcards[theplayer] = 1
|
||||
for player in maxcards:
|
||||
maxcards[player] = int(maxcards[player] / 2)
|
||||
|
||||
word = input("Enter the weekly word: ").replace(" ","").lower()
|
||||
wordspace = []
|
||||
places = len(word)
|
||||
while places > 0:
|
||||
wordspace.append("")
|
||||
places -= 1
|
||||
|
||||
for card in candidates:
|
||||
wordindex = 0
|
||||
go = True
|
||||
theplayer = card["player"]
|
||||
if maxcards[theplayer] > 0:
|
||||
for space in wordspace:
|
||||
if go:
|
||||
if space == "":
|
||||
if word[wordindex] in card["card"]:
|
||||
newspace = word[wordindex].upper() + " " + card["card"] + " – <a href=\"" + card["url"] + "\">" + card["player"] + "</a>"
|
||||
wordspace[wordindex] = newspace
|
||||
go = False
|
||||
theplayer = card["player"]
|
||||
maxcards[theplayer] -= 1
|
||||
wordindex += 1
|
||||
|
||||
remaining = []
|
||||
spaceindex = 0
|
||||
for space in wordspace:
|
||||
if space == "":
|
||||
remaining.append(word[spaceindex].upper())
|
||||
spaceindex += 1
|
||||
|
||||
if len(remaining) > 0:
|
||||
print("Still need " + ", ".join(remaining))
|
||||
else:
|
||||
print("\n" + "\n".join(wordspace) + "\n")
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue