Skip to content

Instantly share code, notes, and snippets.

Last active June 11, 2020 00:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save oasic/ee87bc898a3cd2afaa6872993b62df86 to your computer and use it in GitHub Desktop.
Markup errors using the GrammarBot API
import requests
def flag_errors(text):
r ="",
data = {'text': text, 'language': 'en-US'},
'x-rapidapi-host': "",
'x-rapidapi-key': "your_rapid_api_key_2a1c27dp1af3afjsn67a3e57142d6",
'content-type': "application/x-www-form-urlencoded"
j = r.json()
new_text = ''
cursor = 0
for match in j["matches"]:
offset = match["offset"]
length = match["length"]
if cursor > offset:
# build new_text from cursor to current offset
new_text += text[cursor:offset]
# next add **word**
new_text += "**" + text[offset:(offset + length)] + "**"
# update cursor
cursor = offset + length
# if cursor < text length, then add remaining text to new_text
if cursor < len(text):
new_text += text[cursor:]
return new_text
flag_errors("We be smart. They be smart too. How doo you spel that wurd?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment