ConDict

Check-in [78adff3d45]
Login

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

Overview
Comment:done import from CSV
Timelines: family | ancestors | descendants | both | testing
Files: files | file ages | folders
SHA1:78adff3d45dcf3e01fa68898452dc1ece75d4d6a
User & Date: zorro 2012-09-11 17:25:27
Context
2012-09-13
18:09
change DB-structure check-in: cf35d5c40f user: zorro tags: testing
2012-09-11
17:25
done import from CSV check-in: 78adff3d45 user: zorro tags: testing
2012-09-09
17:28
update DB check-in: cd1965a94f user: zorro tags: testing
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to condt.py.

35
36
37
38
39
40
41

42
43
44
45
46
47
48
..
70
71
72
73
74
75
76

77
78
79
80
81
82
83
...
434
435
436
437
438
439
440







































        '.chpassword': {'desc': 'change current password', 'command': None},
        '.list': {'desc': 'list users words', 'command': None},
        '.en': {'desc': 'dictionary mode English to Russian', 'command': None},
        '.ru': {'desc': 'dictionary mode Russian to English', 'command': None},
        '.add': {'desc': 'add new words', 'command': None},
        '.connect': {'desc': 'test connection', 'command': None},
        '.export': {'desc': 'export user dictionary to CSV file', 'command': None},

        '.edit': {'desc': 'edit words', 'command': None},
        '.delete': {'desc': 'delete words', 'command': None},
        '.exit': {'desc': 'quit from program', 'command': None},
        }
    def __init__(self, name, dbfile):
        super().__init__(name, dbfile)       
        self.__pcounter = 3
................................................................................
        self.COMMANDS['.chpassword']['command'] = self.command_chpassword
        self.COMMANDS['.list']['command'] = self.command_list
        self.COMMANDS['.en']['command'] = self.command_en
        self.COMMANDS['.ru']['command'] = self.command_ru
        self.COMMANDS['.add']['command'] = self.command_add
        self.COMMANDS['.connect']['command'] = self.command_connect
        self.COMMANDS['.export']['command'] = self.command_export

        self.COMMANDS['.edit']['command'] = self.command_edit
        self.COMMANDS['.delete']['command'] = self.command_delete

    def hash_pass(self, password):
        result = bytes(password.strip() + SALT, 'utf-8')
        result = bytes(hashlib.md5(result).hexdigest(), 'utf-8')
        return hashlib.sha1(result).hexdigest()
................................................................................
            pattern = for_search + '%' 
            sql_str += "WHERE `term`.`en` LIKE (?) AND `user_id`=(?) ORDER BY `translate`.`id`"
        else:
            pattern = for_search
            sql_str += "WHERE `translate`.`id`=(?) AND `user_id`=(?) ORDER BY `translate`.`id`"
        cur.execute(sql_str, (pattern, self.user_id))
        return cur.fetchall()














































>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
        '.chpassword': {'desc': 'change current password', 'command': None},
        '.list': {'desc': 'list users words', 'command': None},
        '.en': {'desc': 'dictionary mode English to Russian', 'command': None},
        '.ru': {'desc': 'dictionary mode Russian to English', 'command': None},
        '.add': {'desc': 'add new words', 'command': None},
        '.connect': {'desc': 'test connection', 'command': None},
        '.export': {'desc': 'export user dictionary to CSV file', 'command': None},
        '.import': {'desc': 'import user dictionary from CSV file (start row=2)', 'command': None},
        '.edit': {'desc': 'edit words', 'command': None},
        '.delete': {'desc': 'delete words', 'command': None},
        '.exit': {'desc': 'quit from program', 'command': None},
        }
    def __init__(self, name, dbfile):
        super().__init__(name, dbfile)       
        self.__pcounter = 3
................................................................................
        self.COMMANDS['.chpassword']['command'] = self.command_chpassword
        self.COMMANDS['.list']['command'] = self.command_list
        self.COMMANDS['.en']['command'] = self.command_en
        self.COMMANDS['.ru']['command'] = self.command_ru
        self.COMMANDS['.add']['command'] = self.command_add
        self.COMMANDS['.connect']['command'] = self.command_connect
        self.COMMANDS['.export']['command'] = self.command_export
        self.COMMANDS['.import']['command'] = self.command_import
        self.COMMANDS['.edit']['command'] = self.command_edit
        self.COMMANDS['.delete']['command'] = self.command_delete

    def hash_pass(self, password):
        result = bytes(password.strip() + SALT, 'utf-8')
        result = bytes(hashlib.md5(result).hexdigest(), 'utf-8')
        return hashlib.sha1(result).hexdigest()
................................................................................
            pattern = for_search + '%' 
            sql_str += "WHERE `term`.`en` LIKE (?) AND `user_id`=(?) ORDER BY `translate`.`id`"
        else:
            pattern = for_search
            sql_str += "WHERE `translate`.`id`=(?) AND `user_id`=(?) ORDER BY `translate`.`id`"
        cur.execute(sql_str, (pattern, self.user_id))
        return cur.fetchall()

    def command_import(self, import_name):
        start = False
        cur = self.connect.cursor()
        try:
            read_csv = csv.reader(open(import_name), delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL)
            for row in read_csv:
                if not start:
                    start = True
                    continue
                en = row[0]
                ru = row[1]
                # check term
                token = hashlib.md5(bytes(prepare_str(en), 'utf-8')).hexdigest()
                # check translate
                cur.execute("SELECT `term` FROM `translate` WHERE `user_id`=(?) AND `term`=(?)", (self.user_id, token))
                if not cur.fetchone():
                    # check term
                    cur.execute("SELECT `token` FROM `term` WHERE `token`=(?)", (token,))
                    if not cur.fetchone():
                        cur.execute("INSERT INTO `term` (`token`, `en`) VALUES ((?), (?))", (token, prepare_str(en)))
                    cur.execute("INSERT INTO `translate` (term,user_id,rus) VALUES (?,?,?)", (token, self.user_id, prepare_str(ru)))
                    translate_id = cur.lastrowid
                    cur.execute("INSERT INTO `progress` (`translate_id`) VALUES (?)", (translate_id,))
                    print("Added: {0}".format(en))
                else:
                    print("Dublicate record: {0}".format(en))
                    continue
        except sqlite3.DatabaseError as e:
            if DEBUG: print(e)
            print("DB error for {0}".format(en))
        except (TypeError, IOError) as er:
            if DEBUG: print(er)
            cur.close()
            print("Please write '.import import_file.csv'")
        else:
            self.connect.commit()
            cur.close()
        return 'import'

Changes to db.sqlite.

cannot compute difference between binary files

Changes to main.py.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#-*- 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







|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#-*- 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