From 4519aedca83b16c967248705dbf673b31c5da213 Mon Sep 17 00:00:00 2001 From: adithyagenie Date: Wed, 18 Jan 2023 07:55:21 +0530 Subject: [PATCH] Play script --- .fleet/settings.json | 0 .gitignore | 5 ++++- helper_scripts/dumpsample.bat | 0 helper_scripts/initsql.bat | 0 helper_scripts/play.bat | 1 + play.bat | 37 +++++++++++++++++++++++++++++++++ play.vbs | 39 +++++++++++++++++++++++++++++++++++ wordle/dictionary.py | 7 ++++++- 8 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 .fleet/settings.json create mode 100644 helper_scripts/dumpsample.bat create mode 100644 helper_scripts/initsql.bat create mode 100644 helper_scripts/play.bat create mode 100644 play.bat create mode 100644 play.vbs diff --git a/.fleet/settings.json b/.fleet/settings.json new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index 6ee3481..1aa1ac1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ maze/__pycache__ maze/modules/__pycache__ saves tetris -wordle-curses/__pycache__ \ No newline at end of file +wordle-curses/__pycache__ +1.json +2.json +3.json \ No newline at end of file diff --git a/helper_scripts/dumpsample.bat b/helper_scripts/dumpsample.bat new file mode 100644 index 0000000..e69de29 diff --git a/helper_scripts/initsql.bat b/helper_scripts/initsql.bat new file mode 100644 index 0000000..e69de29 diff --git a/helper_scripts/play.bat b/helper_scripts/play.bat new file mode 100644 index 0000000..9cddf3f --- /dev/null +++ b/helper_scripts/play.bat @@ -0,0 +1 @@ +start python %~f1/starter.py \ No newline at end of file diff --git a/play.bat b/play.bat new file mode 100644 index 0000000..85f4f6d --- /dev/null +++ b/play.bat @@ -0,0 +1,37 @@ +:: Play the game +@ECHO off +cls +:start +ECHO. +ECHO 1. Play game +ECHO 2. Initialise SQL login creds +ECHO 3. Dump sample data +ECHO 4. Exit +set choice= +set /p choice=Choice? +if not '%choice%'=='' set choice=%choice:~0,1% +if '%choice%'=='1' goto play +if '%choice%'=='2' goto initsql +if '%choice%'=='3' goto dump +if '%choice%'=='4' goto end +ECHO "%choice%" is not valid, try again +ECHO. +goto start + +:play +start cmd /c "python %~dp0%~1/starter.py" +move nul 2>&0 +goto end + +:initsql +start cmd /c "python %~dp0%~1/starter.py initsql" +move nul 2>&0 +goto end + +:dump +start cmd /c "python %~dp0%~1/starter.py dumpsample" +move nul 2>&0 +goto end + +:end +pause \ No newline at end of file diff --git a/play.vbs b/play.vbs new file mode 100644 index 0000000..1bc4241 --- /dev/null +++ b/play.vbs @@ -0,0 +1,39 @@ +strTitle = "Labyrinth" +strMsg = "1. Play" & vbCr +strMsg = strMsg & "2. Initialise SQL creds" & vbCR +strMsg = strMsg & "3. Dump sample data" & vbCR +strMsg = strMsg & "Select choice:" & vbCR +Dim oShell +Set oShell = WScript.CreateObject ("WScript.Shell") +Dim folderName +folderName = "." +Dim fso +Set fso = CreateObject("Scripting.FileSystemObject") +Dim fullpath +fullpath = fso.GetAbsolutePathName(folderName) +const quote = """" +Dim command +Do + inp01 = InputBox(strMsg,strTitle) + OK = True + Select Case inp01 + Case "1" + command = quote + "C:\Program Files\PowerShell\7\pwsh.exe" & quote & "-ExecutionPolicy ByPass -NoExit -Command & " & quote & "E:\Programs\Miniconda3\shell\condabin\conda-hook.ps1" & quote & "; conda activate " & quote & "E:\Programs\Miniconda3" & quote & "; conda activate adi; python " & fullpath & "\starter.py" + command = "cmd.exe /C python "+fullpath+"\starter.py" + msgBox command + oShell.run ""+command + Case "2" + command = quote + "C:\Program Files\PowerShell\7\pwsh.exe" & quote & "-ExecutionPolicy ByPass -NoExit -Command & " & quote & "E:\Programs\Miniconda3\shell\condabin\conda-hook.ps1" & quote & "; conda activate " & quote & "E:\Programs\Miniconda3" & quote & "; conda activate adi; python " & fullpath & "\starter.py initsql" + command = "cmd.exe /C python "+fullpath+"\starter.py initsql" + oShell.run ""+command + Case "3" + command = quote + "C:\Program Files\PowerShell\7\pwsh.exe" & quote & "-ExecutionPolicy ByPass -NoExit -Command & " & quote & "E:\Programs\Miniconda3\shell\condabin\conda-hook.ps1" & quote & "; conda activate " & quote & "E:\Programs\Miniconda3" & quote & "; conda activate adi; python " & fullpath & "\starter.py dumpsample" + command = "cmd.exe /C python "+fullpath+"\starter.py dumpsample" + oShell.run ""+command + Case "" + WScript.quit + Case Else + MsgBox "You made an incorrect selection!",64,strTitle + OK = False + End Select +Loop While Not OK diff --git a/wordle/dictionary.py b/wordle/dictionary.py index a7f0a9a..f67fc61 100644 --- a/wordle/dictionary.py +++ b/wordle/dictionary.py @@ -1,5 +1,5 @@ import pickle - +import json import requests with open("credentials.pickle", "rb") as f: @@ -9,6 +9,7 @@ with open("credentials.pickle", "rb") as f: if d["credtype"] == "oxfordapi": app_id = d["app_id"] app_key = d["app_key"] + break except EOFError: pass @@ -17,6 +18,7 @@ language = "en-us" def defnsyn(w): """Returns definition and synonym of said word""" + f = open("log.txt", "a") url = ( r"https://od-api.oxforddictionaries.com:443/api/v2/entries/" + language @@ -25,13 +27,16 @@ def defnsyn(w): ) r = requests.get(url, headers={"app_id": app_id, "app_key": app_key}) if r.status_code != 200: + f.write("GOT "+str(r.status_code)) return None, None res = r.json() + f.write(json.dumps(res)) s1 = res["results"][0]["lexicalEntries"] lexicalCategories = [] synonyms = [] defn = "" try: + defn = res["entries"]["senses"]["definitions"][0] if len(s1) > 1: for i in range(len(s1)): lexicalCategories.append(s1[i]["lexicalCategory"]["id"])