Skip to content

Commit

Permalink
Add new version
Browse files Browse the repository at this point in the history
  • Loading branch information
svenko99 committed Sep 9, 2023
1 parent b9d7e11 commit b587581
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ The Spell Checker Alfred Workflow allows you to quickly check the spelling of se
<img src="https://github.com/svenko99/alfred-spell-checker/blob/main/images/tutorial2.png">
</details>

## Limitations

- The workflow only supoorts 400 characters per request. If the selected text is longer than 400 characters, the workflow will only check the first 400 characters.

## Usage

1. Select the text you want to check the spelling for.
Expand Down
Binary file modified Spell Checker.alfredworkflow
Binary file not shown.
60 changes: 33 additions & 27 deletions src/spell_checker.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
import json
import sys
import http.client
from urllib.parse import quote

import sys
import gzip
import json

def get_spell_check(text):
conn = http.client.HTTPSConnection("services.gingersoftware.com")

conn.request(
"GET",
"/Ginger/correct/jsonSecured/GingerTheTextFull?clientVersion=2.0&lang=US&text="
+ quote(text)
+ "&apiKey=6ae0c3a0-afdc-4532-a810-82ded0054236",
def spell_check(text):
conn = http.client.HTTPSConnection("orthographe.reverso.net")
payload = json.dumps(
{
"englishDialect": "indifferent",
"autoReplace": True,
"getCorrectionDetails": True,
"interfaceLanguage": "en",
"locale": "",
"language": "eng",
"text": text,
"originalText": "",
"origin": "ginger.web",
"isHtml": False,
"IsUserPremium": False,
}
)

headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0",
"Accept": "text/json",
"Accept-Language": "en-GB,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/*+json",
"Connection": "keep-alive",
}

conn.request("POST", "/api/v1/Spelling/", payload, headers)
res = conn.getresponse()
data = res.read()
conn.close()
return json.loads(data.decode("utf-8"))


def process_data(text, data):
result = text

for suggestion in reversed(data["Corrections"]):
start = suggestion["From"]
end = suggestion["To"]

if suggestion["Suggestions"]:
suggest = suggestion["Suggestions"][0]
result = result[:start] + suggest["Text"] + result[end + 1 :]
decoded_data = gzip.decompress(data).decode("utf-8")
json_data = json.loads(decoded_data)

return result
return json_data["text"]


if __name__ == "__main__":
ALFRED_QUERY = " ".join(sys.argv[1:])
data = get_spell_check(ALFRED_QUERY)
sys.stdout.write(process_data(ALFRED_QUERY, data))
sys.stdout.write(spell_check(ALFRED_QUERY))

0 comments on commit b587581

Please sign in to comment.