ConDict

Check-in [f0f548322f]
Login

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

Overview
Comment:add 'encoding' in export/import
Timelines: family | ancestors | descendants | both | testing
Files: files | file ages | folders
SHA1:f0f548322f7fb94072f8df3f9f737ea3b469ebe6
User & Date: zorro 2012-09-15 10:31:04
Context
2012-09-15
19:36
create test's check-in: ce14522219 user: zorro tags: testing
10:31
add 'encoding' in export/import check-in: f0f548322f user: zorro tags: testing
2012-09-13
18:40
change help output check-in: 153cc0adaf user: zorro tags: testing
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to condt.py.

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
...
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
            'full': 'import user dictionary form CSV file, encoding UTF-8'},
        '.edit': {'desc': 'edit words', 'command': None,
            'full': 'edit word/pattern, search by ID ".edit ID"'},
        '.delete': {'desc': 'delete words', 'command': None,
            'full': 'delete word/pattern, search by ID, ".delete ID"'},
        '.exit': {'desc': 'quit from program', 'command': None,
            'full': 'quit form program'},
        '.test': {'desc': 'start test (default en)', 'command': None,
            'full': 'test'},
        '.testru': {'desc': 'start ru-test', 'command': None,
            'full': 'test'},
        '.testmix': {'desc': 'start en-ru test', 'command': None,
            'full': 'test'},
        }
    def __init__(self, name, dbfile, ctest=10):
        super().__init__(name, dbfile)       
        self.__pcounter = 3
        self.ctest = ctest
        self.init_command()
        self.user_id = self.get_user()
................................................................................
        cur.execute(sql_list3, (translate_id,))
        return translate_id

    def command_export(self, arg=None):
        """export all user dictionary in CSV file"""
        global EXPORT_NAME, DEBUG
        if arg:
            export_name = arg + ".csv"
        else:
            d = datetime.date.today()
            export_name = EXPORT_NAME + d.strftime("%Y_%m_%d") + ".csv"
        try:
            cur = self.connect.cursor()
            writer_csv = csv.writer(open(export_name, 'w'), delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL)
            writer_csv.writerow(['ENGLISH','RUSSIAN'])
            sql_list = "SELECT `term`.`en`, `translate`.`rus` FROM `translate` LEFT JOIN `term` ON (`translate`.`term`=`term`.`token`) WHERE `translate`.`user_id`=(?) ORDER BY `term`.`en`, `translate`.`rus`"
            cur.execute(sql_list, (self.user_id,))
            for result in cur.fetchall():
                writer_csv.writerow(result)
        except Exception as e:
            if DEBUG: print(e)
................................................................................
        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
                if len(row) < 2: continue
                en = row[0]
                ru = row[1]







|
|
|
|
|
|







 







|





|







 







|







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
...
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
            'full': 'import user dictionary form CSV file, encoding UTF-8'},
        '.edit': {'desc': 'edit words', 'command': None,
            'full': 'edit word/pattern, search by ID ".edit ID"'},
        '.delete': {'desc': 'delete words', 'command': None,
            'full': 'delete word/pattern, search by ID, ".delete ID"'},
        '.exit': {'desc': 'quit from program', 'command': None,
            'full': 'quit form program'},
        # '.test': {'desc': 'start test (default en)', 'command': None,
        #     'full': 'test'},
        # '.testru': {'desc': 'start ru-test', 'command': None,
        #     'full': 'test'},
        # '.testmix': {'desc': 'start en-ru test', 'command': None,
        #     'full': 'test'},
        }
    def __init__(self, name, dbfile, ctest=10):
        super().__init__(name, dbfile)       
        self.__pcounter = 3
        self.ctest = ctest
        self.init_command()
        self.user_id = self.get_user()
................................................................................
        cur.execute(sql_list3, (translate_id,))
        return translate_id

    def command_export(self, arg=None):
        """export all user dictionary in CSV file"""
        global EXPORT_NAME, DEBUG
        if arg:
            export_name = arg
        else:
            d = datetime.date.today()
            export_name = EXPORT_NAME + d.strftime("%Y_%m_%d") + ".csv"
        try:
            cur = self.connect.cursor()
            writer_csv = csv.writer(open(export_name, 'w', newline='', encoding='utf-8'), dialect='excel', delimiter=';', quoting=csv.QUOTE_ALL)
            writer_csv.writerow(['ENGLISH','RUSSIAN'])
            sql_list = "SELECT `term`.`en`, `translate`.`rus` FROM `translate` LEFT JOIN `term` ON (`translate`.`term`=`term`.`token`) WHERE `translate`.`user_id`=(?) ORDER BY `term`.`en`, `translate`.`rus`"
            cur.execute(sql_list, (self.user_id,))
            for result in cur.fetchall():
                writer_csv.writerow(result)
        except Exception as e:
            if DEBUG: print(e)
................................................................................
        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, newline='', encoding='utf-8'), dialect='excel', delimiter=';', quoting=csv.QUOTE_ALL)
            for row in read_csv:
                if not start:
                    start = True
                    continue
                if len(row) < 2: continue
                en = row[0]
                ru = row[1]