-
Notifications
You must be signed in to change notification settings - Fork 0
/
nytinator3000.py
73 lines (57 loc) · 2.15 KB
/
nytinator3000.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
from urllib.request import urlopen
from datetime import date
def wordle():
url = "https://www.nytimes.com/svc/wordle/v2/" + str(date.today()) +".json"
response = urlopen(url)
data = json.loads(response.read())
print("The solution today is: "+ (data["solution"]).upper())
return
def connections():
url = "https://www.nytimes.com/svc/connections/v1/" + str(date.today()) + ".json"
response = urlopen(url)
data = json.loads(response.read())
groups_list = list(data["groups"])
items_list = list(data["groups"].values())
difficulties = ["Straightforward","Intermediate","Hard","Tricky"]
for i in range(0,4):
print("Difficulty: " + str(difficulties[i]))
print(groups_list[i] + ":\n" + ", ".join(items_list[i]["members"]) + "\n")
return
def strands():
url = "https://www.nytimes.com/games-assets/strands/" + str(date.today()) + ".json"
response = urlopen(url)
data = json.loads(response.read())
spangram = data["spangram"]
solutions_list = list(data["solutions"])
answers_list = []
print("Spangram: " + str(spangram))
for i in range(0, solutions_list.index(str(spangram))):
answers_list.append(solutions_list[i])
print("Solutions: " + ", ".join(answers_list))
return
def mini():
url = "https://www.nytimes.com/svc/crosswords/v6/puzzle/mini.json"
response = urlopen(url)
data = json.loads(response.read())
cells = data["body"][0]["cells"]
answers_list = []
row = 0
for i in range(0, len(cells)):
if not cells[i]:
answers_list.append("_")
elif cells[i]["clues"][0] > row:
row += 1
answers_list.append("\n" + cells[i]["answer"])
else:
answers_list.append(cells[i]["answer"])
print("Solutions across:\n" + "".join(answers_list))
return
func_list = [wordle, connections, strands, mini]
def menu():
print("Which NYT game would you like the answer(s) to?\n---------------")
print("(1) Wordle\n(2) Connections\n(3) Strands\n(4) Mini Crossword\n")
choice = int(input("Please enter a number: ").strip())
func_list[choice-1]()
return
menu()