Skip to content

Instantly share code, notes, and snippets.

@scari
Last active February 17, 2017 06:04
Show Gist options
  • Save scari/c2d27e378c6b48f13748 to your computer and use it in GitHub Desktop.
Save scari/c2d27e378c6b48f13748 to your computer and use it in GitHub Desktop.
autospacing
#!/usr/bin/env python3
import sys
import re
import json
import requests
from colorama import init, Fore, Back, Style
URL = 'https://m.search.naver.com/p/csearch/dcontent/spellchecker.nhn'
def get(url):
return requests.get(url, headers={'Referer':'https://search.naver.com/search.naver', 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:48.0) Gecko/20100101 Firefox/48.0'}).text
def main(q):
result = None
response = get(URL + '?_callback=window.__jindo2_callback._spellingCheck_0&q=' + q)
matched = re.search(r'.*?\((.*)\);', response)
if matched:
obj = json.loads(matched.group(1))
result = obj['message']['result']
print('errata_count : {}'.format(result['errata_count']))
html = result['html']
html = re.sub(r"<span class='re_red'>", Fore.RED, html)
html = re.sub(r"<span class='re_green'>", Fore.GREEN, html)
html = re.sub(r"<span class='re_purple'>", Fore.MAGENTA, html)
html = re.sub(r'<\/?.*?>', Style.RESET_ALL, html)
print('after : ' + html)
else:
print('no result.')
if __name__ == '__main__':
try:
q = ' '.join(sys.argv[1:])
except IndexError:
sys.exit(1)
main(q)
'''
print('')
print('HELP : ', end='')
print(Fore.RED + u'맞춤법', end=' ')
print(Fore.GREEN + u'띄어쓰기', end=' ')
print(Fore.MAGENTA + u'표준어 의심단어')
print(Style.RESET_ALL)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment