-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordle-hacker.py
69 lines (66 loc) · 2.79 KB
/
wordle-hacker.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
try:
import platform
import os
from datetime import datetime
import requests
from colorama import init, Fore, Style
except ModuleNotFoundError:
sys = platform.system()
if "mac" not in sys:
os.system("pip install requests colorama")
else:
print(Fore.RED + "No module named requests or colorama (install the missing modules then restart the script)")
# Initialize colorama
init(autoreset=True)
sys = platform.system()
if sys == "Linux" :
os.system("clear")
elif sys == "Windows":
os.system("cls")
else:
os.system("clear")
def checker(date_str):
try:
# Try to parse the input string to a datetime object
parsed_date = datetime.strptime(date_str, "%Y-%m-%d")
# Check if the formatted string matches the original string to catch invalid dates like '2020-13-01'
return parsed_date.strftime("%Y-%m-%d") == date_str
except ValueError:
return False
def main():
try:
url = "https://www.nytimes.com/svc/wordle/v2/"
print(Fore.CYAN + "Do you want today's answer or a specific date?")
option = int(input(Fore.GREEN + "(1: today, 2: specific date): "))
if option == 1:
date = str(datetime.now().date())
url += date + ".json"
try:
response = requests.get(url).json()
answer = response['solution']
print(Fore.MAGENTA + f"Found the answer for today's Wordle: {Fore.GREEN}{answer}")
except Exception as e:
print(Fore.RED + f"Error fetching today's Wordle answer: {e}")
elif option == 2:
date = input(Fore.CYAN + "Enter the date you want (ex: 2020-09-09): \n")
if checker(date):
url = f"https://www.nytimes.com/svc/wordle/v2/{date}.json"
try:
response = requests.get(url).json()
if "solution" in response:
answer = response['solution']
print(Fore.MAGENTA + f"Found the answer for the date you wanted: {Fore.GREEN}{answer}")
else:
print(Fore.RED + "Couldn't get the answer for that date...")
except Exception as e:
print(Fore.RED + f"Error fetching the Wordle answer for {date}: {e}")
else:
print(Fore.RED + "You entered the date in the wrong format.\nExample of what you must enter: year-month-day (2020-09-09)")
else:
print(Fore.RED + "Wrong option chosen")
except KeyError as error :
print(f"{Fore.BLUE} This error has been happened : \n {Fore.RED}{error}")
if __name__ == "__main__":
main()
# made with love by DarkBlud
# TG : @DarkBlud