ConDict

Check-in [70ae59edca]
Login

Check-in [70ae59edca]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add spelling, add bug in utf-8
Timelines: family | ancestors | testing
Files: files | file ages | folders
SHA1: 70ae59edca580bad60a48a5a5ee38f29502a21d7
User & Date: zorro 2012-12-05 19:11:20.278
Context
2012-12-05
19:11
add spelling, add bug in utf-8 Leaf check-in: 70ae59edca user: zorro tags: testing
2012-10-17
11:10
fixed bug in command .info check-in: e03a7f02c8 user: alzay tags: testing
Changes
Unified Diff Ignore Whitespace Patch
Changes to aside.py.
1
2
3
4
5
6
7

8
9
10
11
12
13
14
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import re, configparser, json, signal
from urllib import request, parse

YANDEX_TRANSLATE_JSON = "http://translate.yandex.net/api/v1/tr.json/translate?"

TEST_CONNECT = "http://ya.ru/"
CHECK_MANY_SPACE = re.compile(r"\s+")
DEFCTEST = 10

def get_config_data(filename):
    global DEFCTEST
    result = {'database': None, 'defuser': None, 'defctest': DEFCTEST, 'debug': False}







>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import re, configparser, json, signal
from urllib import request, parse

YANDEX_TRANSLATE_JSON = "http://translate.yandex.net/api/v1/tr.json/translate?"
YANDEX_SPELL_JSON = "http://speller.yandex.net/services/spellservice.json/checkText?"
TEST_CONNECT = "http://ya.ru/"
CHECK_MANY_SPACE = re.compile(r"\s+")
DEFCTEST = 10

def get_config_data(filename):
    global DEFCTEST
    result = {'database': None, 'defuser': None, 'defctest': DEFCTEST, 'debug': False}
58
59
60
61
62
63
64




























65
66
67
68
69
70
71
        try:
            from_url = conn.read().decode('utf-8')
            result = json.loads(from_url)
        except Exception as e:
            print(e)
    conn.close()
    return result





























def get_test_connection():
    global TEST_CONNECT
    print("check connection...")
    try:
        conn = request.urlopen(TEST_CONNECT)
        result = True if conn.getcode() == 200 else False







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
        try:
            from_url = conn.read().decode('utf-8')
            result = json.loads(from_url)
        except Exception as e:
            print(e)
    conn.close()
    return result

def check_spell(for_spelling, spell_type='en'):
    global YANDEX_SPELL_JSON
    result = False
    # options = IGNORE_DIGITS(2) + IGNORE_DIGITS(4) + IGNORE_CAPITALIZATION(512) + [BY_WORDS(256)]
    params = {'lang': spell_type, 'text': for_spelling, 'format': 'plane', 'options': 518}
    prepate_url = parse.urlencode(params, encoding="utf-8")
    erro_codes = ("ERROR_UNKNOWN_WORD",
        "ERROR_REPEAT_WORD",
        "ERROR_CAPITALIZATION",
        "ERROR_TOO_MANY_ERRORS")
    try:
        conn = request.urlopen(YANDEX_SPELL_JSON + prepate_url, None, 1)
        if conn.status == 200:
            from_url = conn.read().decode('utf-8')
            result = json.loads(from_url)
    except Exception as e:
        print("Not connection\nError: ".format(e))
        return result
    else:
        conn.close()
    if len(result) > 0:
        print("Spelling: ", end="")
        for_result = []
        for res in result:
            for_result.append("{0} -> {1}".format(res['word'], res['s']))
        print("; ".join(for_result))
    return 0

def get_test_connection():
    global TEST_CONNECT
    print("check connection...")
    try:
        conn = request.urlopen(TEST_CONNECT)
        result = True if conn.getcode() == 200 else False
Changes to condt.py.
288
289
290
291
292
293
294

295
296
297
298
299
300
301
        # found in offline DB
        alreadyEx = self.alreadyex(text, tr_type)
        if alreadyEx: 
            if DEBUG: print("[offline]")
            return alreadyEx[0]
        if not self.online:
            return "Offline, please test connect with '.connect' command"

        result = get_translate(text, tr_type)
        if not result or result['code'] != 200:
            self.command_connect()
            return "Error, not foud translate"
        return result['text']

    def command_list(self, pattern=None):







>







288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
        # found in offline DB
        alreadyEx = self.alreadyex(text, tr_type)
        if alreadyEx: 
            if DEBUG: print("[offline]")
            return alreadyEx[0]
        if not self.online:
            return "Offline, please test connect with '.connect' command"
        check_spell(text, tr_type)
        result = get_translate(text, tr_type)
        if not result or result['code'] != 200:
            self.command_connect()
            return "Error, not foud translate"
        return result['text']

    def command_list(self, pattern=None):
Changes to main.py.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

from aside import *
from condt import Condt
import getpass, os

CONF_NAME = 'condt.conf' 
PREFIX = "{0}@ConDict[{1}]$"
WELCOM = """****************************************************
*** Good day.                                    ***
*** For help, use the command ".help", nice work.***
****************************************************"""

def main():
    global CONF_NAME, PREFIX








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

from aside import *
from condt import Condt
import getpass, os

CONF_NAME = 'condt.conf' 
PREFIX = "{0}@condict[{1}]$"
WELCOM = """****************************************************
*** Good day.                                    ***
*** For help, use the command ".help", nice work.***
****************************************************"""

def main():
    global CONF_NAME, PREFIX