Beispiel #1
0
def test_tsv_tag_modified():
    col = getEmptyCol()
    mm = col.models
    m = mm.current()
    note = mm.newField("Top")
    mm.addField(m, note)
    mm.save(m)
    n = col.newNote()
    n["Front"] = "1"
    n["Back"] = "2"
    n["Top"] = "3"
    n.add_tag("four")
    col.addNote(n)

    # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
    with NamedTemporaryFile(mode="w", delete=False) as tf:
        tf.write("1\tb\tc\n")
        tf.flush()
        i = TextImporter(col, tf.name)
        i.initMapping()
        i.tagModified = "boom"
        i.run()
        clear_tempfile(tf)

    n.load()
    assert n["Front"] == "1"
    assert n["Back"] == "b"
    assert n["Top"] == "c"
    assert "four" in n.tags
    assert "boom" in n.tags
    assert len(n.tags) == 2
    assert i.updateCount == 1

    col.close()
Beispiel #2
0
def vocabulous():

    words_list, words_dict = get_entries()
    wordswritten = write_definitions("vocabulous.csv", words_list, words_dict)

    file = "vocabulous.csv"
    # select deck
    did = mw.col.decks.id("Default")
    mw.col.decks.select(did)
    # set note type for deck
    m = mw.col.models.byName("Basic")
    deck = mw.col.decks.get(did)
    deck['mid'] = m['id']
    mw.col.decks.save(deck)
    # import into the collection
    ti = TextImporter(mw.col, file)
    ti.allowHTML = True
    ti.importMode = 1
    ti.initMapping()
    ti.run()

    # get the number of cards in the current collection, which is stored in
    # the main window
    cardCount = mw.col.cardCount()
    # show a message box
    showInfo("Added %d new words. Now %d words in total." %
             (wordswritten, cardCount))
Beispiel #3
0
def test_tsv_tag_multiple_tags():
    deck = getEmptyCol()
    mm = deck.models
    m = mm.current()
    f = mm.newField("Top")
    mm.addField(m, f)
    mm.save(m)
    n = deck.newNote()
    n["Front"] = "1"
    n["Back"] = "2"
    n["Top"] = "3"
    n.addTag("four")
    n.addTag("five")
    deck.addNote(n)

    # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
    with NamedTemporaryFile(mode="w", delete=False) as tf:
        tf.write("1\tb\tc\n")
        tf.flush()
        i = TextImporter(deck, tf.name)
        i.initMapping()
        i.tagModified = "five six"
        i.run()
        clear_tempfile(tf)

    n.load()
    assert n["Front"] == "1"
    assert n["Back"] == "b"
    assert n["Top"] == "c"
    assert list(sorted(n.tags)) == list(sorted(["four", "five", "six"]))

    deck.close()
Beispiel #4
0
 def setupImporter(self, temp_file_path):
     self.importer = TextImporter(self.mw.col, str(temp_file_path))
     self.importer.initMapping()
     self.importer.allowHTML = True
     self.importer.importMode = self.frm.importMode.currentIndex()
     self.mw.pm.profile['importMode'] = self.importer.importMode
     self.importer.delimiter = ';'
Beispiel #5
0
def test_csv_tag_only_if_modified():
    deck = getEmptyCol()
    mm = deck.models
    m = mm.current()
    f = mm.newField("Left")
    mm.addField(m, f)
    mm.save(m)
    n = deck.newNote()
    n["Front"] = "1"
    n["Back"] = "2"
    n["Left"] = "3"
    deck.addNote(n)

    # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
    with NamedTemporaryFile(mode="w", delete=False) as tf:
        tf.write("1,2,3\n")
        tf.flush()
        i = TextImporter(deck, tf.name)
        i.initMapping()
        i.tagModified = "right"
        i.run()
        clear_tempfile(tf)

    n.load()
    assert n.tags == []
    assert i.updateCount == 0

    deck.close()
Beispiel #6
0
def test_csv():
    deck = getEmptyDeck()
    file = unicode(os.path.join(testDir, "support/text-2fields.txt"))
    i = TextImporter(deck, file)
    i.initMapping()
    i.run()
    # four problems - too many & too few fields, a missing front, and a
    # duplicate entry
    assert len(i.log) == 5
    assert i.total == 5
    # if we run the import again, it should update instead
    i.run()
    assert len(i.log) == 10
    assert i.total == 5
    # but importing should not clobber tags if they're unmapped
    n = deck.getNote(deck.db.scalar("select id from notes"))
    n.addTag("test")
    n.flush()
    i.run()
    n.load()
    assert n.tags == ['test']
    # if add-only mode, count will be 0
    i.importMode = 1
    i.run()
    assert i.total == 0
    # and if dupes mode, will reimport everything
    assert deck.cardCount() == 5
    i.importMode = 2
    i.run()
    # includes repeated field
    assert i.total == 6
    assert deck.cardCount() == 11
    deck.close()
Beispiel #7
0
def test_csv_tag_only_if_modified():
    deck = getEmptyCol()
    mm = deck.models
    m = mm.current()
    f = mm.newField("Left")
    mm.addField(m, f)
    mm.save(m)
    n = deck.newNote()
    n["Front"] = "1"
    n["Back"] = "2"
    n["Left"] = "3"
    deck.addNote(n)

    with NamedTemporaryFile(mode="w") as tf:
        tf.write("1,2,3\n")
        tf.flush()
        i = TextImporter(deck, tf.name)
        i.initMapping()
        i.tagModified = "right"
        i.run()

    n.load()
    assert n.tags == []
    assert i.updateCount == 0

    deck.close()
Beispiel #8
0
def test_tsv_tag_multiple_tags():
    deck = getEmptyCol()
    mm = deck.models
    m = mm.current()
    f = mm.newField("Top")
    mm.addField(m, f)
    mm.save(m)
    n = deck.newNote()
    n["Front"] = "1"
    n["Back"] = "2"
    n["Top"] = "3"
    n.addTag("four")
    n.addTag("five")
    deck.addNote(n)

    with NamedTemporaryFile(mode="w") as tf:
        tf.write("1\tb\tc\n")
        tf.flush()
        i = TextImporter(deck, tf.name)
        i.initMapping()
        i.tagModified = "five six"
        i.run()

    n.load()
    assert n["Front"] == "1"
    assert n["Back"] == "b"
    assert n["Top"] == "c"
    assert list(sorted(n.tags)) == list(sorted(["four", "five", "six"]))

    deck.close()
Beispiel #9
0
def test_tsv_tag_modified():
    deck = getEmptyCol()
    mm = deck.models
    m = mm.current()
    f = mm.newField("Top")
    mm.addField(m, f)
    mm.save(m)
    n = deck.newNote()
    n["Front"] = "1"
    n["Back"] = "2"
    n["Top"] = "3"
    n.addTag("four")
    deck.addNote(n)

    with NamedTemporaryFile(mode="w") as tf:
        tf.write("1\tb\tc\n")
        tf.flush()
        i = TextImporter(deck, tf.name)
        i.initMapping()
        i.tagModified = "boom"
        i.run()

    n.load()
    assert n["Front"] == "1"
    assert n["Back"] == "b"
    assert n["Top"] == "c"
    assert "four" in n.tags
    assert "boom" in n.tags
    assert len(n.tags) == 2
    assert i.updateCount == 1

    deck.close()
Beispiel #10
0
 def __init__(self, file):
     super(DeckChooser, self).__init__(mw)
     self.setupUi(self)
     self.importer = TextImporter(mw.col, file)
     self.importer.delimiter = "\t"
     self.importer.importMode = 0
     self.importer.allowHTML = True
     self.setup_decks()
     self.exec_()
Beispiel #11
0
    def _importFileToCards(file, model_name):
        deck_id = mw.col.decks.id(":Expressions")
        mw.col.decks.select(deck_id)

        m = mw.col.models.byName(model_name)
        deck = mw.col.decks.get(deck_id)

        deck['mid'] = m['id']
        mw.col.decks.save(deck)
        m['did'] = deck_id

        importer = TextImporter(mw.col, file)
        importer.allowHTML = True
        importer.initMapping()
        importer.run()
Beispiel #12
0
def import_csv(csvFile, lang, book, chapter):
    try:
        deck = getEmptyDeck()
    except pysqlite2.dbapi2.OperationalError as e:
        print e, "you probably have Anki open while you are running this; run this as a plugin from within Anki or close Anki and run this."
        sys.exit(1)
    m = deck.models.byName("Basic")
    deck.models.setCurrent(m)
    # set 'Import' as the target deck
    m['did'] = deck.decks.id(lang + "::" + book + "::" + chapter)
    deck.models.save(m)
    i = TextImporter(deck, csvFile)
    i.initMapping()
    i.run()
    deck.save()
    deck.close()
def importfile(filename, deck, type):
	try:
		file = join(dirname(realpath(__file__)), filename)
		did = mw.col.decks.id(deck)
		mw.col.decks.select(did)
		m = mw.col.models.byName(type)
		deck = mw.col.decks.get(did)
		deck['mid'] = m['id']
		mw.col.decks.save(deck)
		m['did'] = did
		ti = TextImporter(mw.col, file)
		ti.initMapping()
		ti.run()
		tooltip('Successfully imported results.')
	except:
		showWarning('<b>Import error</b><br>Make sure that the notetype and deck exist and that you have enough fields.')
Beispiel #14
0
def drv(col):
    cwd = os.getcwd()
    flist = glob.glob('????.txt')
    for inf in flist:
        textf = 'economist.words.' + inf
        deckname = textf.rstrip('.txt')
        textf = os.path.join(cwd, textf)
        print(textf)
        deckid = col.decks.id(deckname)

        ti = TextImporter(col, textf)
        ti.model['did'] = deckid
        col.decks.select(deckid)

        ti.delimiter = '\t'
        ti.initMapping()
        ti.run()
def importFile(filename):
    name = filename.rsplit('/', 1)[-1].rsplit('.', 1)[0]
    # select deck
    did = mw.col.decks.id(name)
    mw.col.decks.select(did)
    # anki defaults to the last note type used in the selected deck
    m = mw.col.models.byName("Basic")
    deck = mw.col.decks.get(did)
    deck['mid'] = m['id']
    mw.col.decks.save(deck)
    # and puts cards in the last deck used by the note type
    m['did'] = did
    # import into the collection
    ti = TextImporter(mw.col, filename)
    ti.initMapping()
    ti.run()
    mw.col.reset()
    mw.reset()
Beispiel #16
0
def txtImporter():
	##select deck     
	# Modify to your own destination deck                               
	did = mw.col.decks.id("Test")                   
	mw.col.decks.select(did)                        
	# set note type for deck                        
	m = mw.col.models.byName("Basic")               
	deck = mw.col.decks.get(did)                    
	#deck['mid'] = m['id']                           
	mw.col.decks.save(deck)  
	# import into the collection
	oriCardCount = mw.col.cardCount()
	ti = TextImporter(mw.col, txtConvertor())
	ti.initMapping()                                
	ti.run()       
	mw.reset()
	CardCount = mw.col.cardCount()
	# show a message box
	showInfo("Cards imported:" + str(CardCount-oriCardCount) + "\n\nCards Count:" + str(CardCount))
Beispiel #17
0
def test_csv():
    deck = getEmptyDeck()
    file = unicode(os.path.join(testDir, "support/text-2fields.txt"))
    i = TextImporter(deck, file)
    i.initMapping()
    i.run()
    # four problems - too many & too few fields, a missing front, and a
    # duplicate entry
    assert len(i.log) == 5
    assert i.total == 5
    # if we run the import again, it should update instead
    i.run()
    assert len(i.log) == 5
    assert i.total == 5
    # if updating is disabled, count will be 0
    i.update = False
    i.run()
    assert i.total == 0
    deck.close()
Beispiel #18
0
def main():
    parser = argparser()
    args = parser.parse_args()

    csv_filename = args.csv_filename
    deck_name = args.deck_name
    apkg_filename = args.apkg_filename
    media_directory = args.media_directory
    model_name = args.model_name

    # this is removed at the end of the program
    TMPDIR = tempfile.mkdtemp()

    collection = anki.Collection(os.path.join(TMPDIR, 'collection.anki2'))

    deck_id = collection.decks.id(deck_name)
    deck = collection.decks.get(deck_id)

    if model_name == 'Image Occlusion Enhanced':
        model = add_io_model(collection)
    else:
        model = collection.models.byName(model_name).copy()

    model['did'] = deck_id

    collection.models.update(model)
    collection.models.setCurrent(model)
    collection.models.save(model)

    importer = TextImporter(collection, csv_filename)
    importer.allowHTML = True
    importer.initMapping()
    importer.run()

    for media_file in os.listdir(media_directory):
        os.symlink(os.path.join(media_directory, media_file),
                   os.path.join(TMPDIR, 'collection.media', media_file))

    export = AnkiPackageExporter(collection)
    export.exportInto(apkg_filename)

    shutil.rmtree(TMPDIR)
Beispiel #19
0
def ImportToAnki(model_name, import_to_deck, *args, **kwargs):
    # get file
    file = kwargs.get("file", None)
    if not file:
        file = getFile(mw,
                       _("Import"),
                       None,
                       key="import",
                       filter=Importers[0][0])
    if not file:
        return
    file = str(file)

    # check default model
    try:
        model = mw.col.models.byName(model_name)
        if not model:
            raise Exception("没有找到【{}】".format(model_name))
    except:
        importFile(mw, settings.deck_template_file)
        try:
            model = mw.col.models.byName(model_name)
        except:
            model = None

    importer = TextImporter(mw.col, file)
    importer.delimiter = "\t"
    importer.importMode = 0
    importer.allowHTML = True
    importer.model = model

    did = mw.col.decks.id(import_to_deck)
    mw.col.conf['curDeck'] = did
    importer.model['did'] = did
    mw.col.decks.select(did)
    importer.mapping = [kwargs.get("first")]
    importer.run()
    mw.reset()
    txt = _("Importing complete.") + "\n"
    if importer.log:
        txt += "\n".join(importer.log)
    showText(txt)
def importFileOutsideGUI(filename):
    pickle_list = loadFromPickle()
    profile_name = pickle_list[1]
    anki_dir = os.path.dirname(os.path.realpath(__file__).rsplit('\\', 2)[0])
    anki_collection = anki_dir + '\\' + profile_name + '\collection.anki2'
    col = Collection(anki_collection)
    name = filename.rsplit('/', 1)[-1].rsplit('.', 1)[0]
    did = col.decks.id(name)
    col.decks.select(did)
    m = col.models.byName("Basic")
    deck = col.decks.get(did)
    deck['mid'] = m['id']
    col.decks.save(deck)
    m['did'] = did
    ti = TextImporter(col, filename)
    ti.initMapping()
    ti.run()
    col.reset()
    mw.reset()
    col.close()
Beispiel #21
0
def testFunction():
    file = u"/home/hollisma/.local/share/Anki2/addons21/myaddon/cards.txt"

    # Select deck
    did = mw.col.decks.id("Vocab")
    mw.col.decks.select(did)

    # Settings for cards
    m = mw.col.models.byName("Cloze")
    deck = mw.col.decks.get(did)
    deck['mid'] = m['id']
    mw.col.decks.save(deck)
    m['did'] = did
    mw.col.models.save(m)

    # Import cards
    ti = TextImporter(mw.col, file)
    ti.initMapping()
    ti.run()

    showInfo('Done!')
Beispiel #22
0
def test_csv2():
    deck = getEmptyDeck()
    mm = deck.models
    m = mm.current()
    f = mm.newField("Three")
    mm.addField(m, f)
    mm.save(m)
    n = deck.newNote()
    n['Front'] = "1"
    n['Back'] = "2"
    n['Three'] = "3"
    deck.addNote(n)
    # an update with unmapped fields should not clobber those fields
    file = unicode(os.path.join(testDir, "support/text-update.txt"))
    i = TextImporter(deck, file)
    i.initMapping()
    i.run()
    n.load()
    assert n['Front'] == "1"
    assert n['Back'] == "x"
    assert n['Three'] == "3"
    deck.close()
Beispiel #23
0
def test_csv2():
    col = getEmptyCol()
    mm = col.models
    m = mm.current()
    note = mm.newField("Three")
    mm.addField(m, note)
    mm.save(m)
    n = col.newNote()
    n["Front"] = "1"
    n["Back"] = "2"
    n["Three"] = "3"
    col.addNote(n)
    # an update with unmapped fields should not clobber those fields
    file = str(os.path.join(testDir, "support", "text-update.txt"))
    i = TextImporter(col, file)
    i.initMapping()
    i.run()
    n.load()
    assert n["Front"] == "1"
    assert n["Back"] == "x"
    assert n["Three"] == "3"
    col.close()
Beispiel #24
0
def importMHT():
    # Ask for the .mht file.
    file_path = getFile(mw, _("Import mht file"), None, key="import")
    if not file_path:
        return
    file_path = unicode(file_path)

    # Convert mht
    parser = Parser(file_path)
    output = parser.run()

    # Creates a temp dir instead of file since windows
    # won't allow subprocesses to access it otherwise.
    # https://stackoverflow.com/questions/15169101/how-to-create-a-temporary-file-that-can-be-read-by-a-subprocess
    try:
        temp_dir = mkdtemp()
        path = os.path.join(temp_dir, 'import.html')

        with open(path, 'w+') as html:
            html.write(output)
            # Move temp images to collection.media
            media_dir = os.path.join(mw.pm.profileFolder(), "collection.media")

            for meta in parser.file_map.values():
                temp_path = meta.get('path')
                new_path = os.path.join(media_dir, meta.get('filename'))
                shutil.move(temp_path, new_path)

        # import into the collection
        ti = TextImporter(mw.col, path)
        ti.delimiter = '\t'
        ti.allowHTML = True
        ti.initMapping()
        MHTImportDialog(mw, ti)

        # Remove file
        os.remove(path)
    finally:
        os.rmdir(temp_dir)
Beispiel #25
0
def importFile(deckId, notes, noteType):
    if len(notes) == 0:
        return


    with open(u"tmp.txt", "w") as f:
        for item in notes:
            f.write("%s\n" % item)

    m = mw.col.models.byName(noteType)
    deck = mw.col.decks.get(deckId)
    deck['mid'] = m['id']
    m['did'] = deckId
    mw.col.decks.save(deck)
    mw.col.models.save(m)


    ti = TextImporter(mw.col, u"tmp.txt")
    ti.delimiter = ","
    ti.initMapping()
    ti.run()

    os.remove(u"tmp.txt")
Beispiel #26
0
def importFlashcards():

    # Import cards
    for notetype in ['Basic', 'Cloze', 'Definition']:

        filename = os.path.expanduser("~/tmp/" + notetype.lower() + ".csv")
        linecount = sum(1 for line in open(filename))
        if linecount > 1:
            # Select deck
            did = mw.col.decks.id(currentDeck)
            mw.col.decks.select(did)
            # Set note type
            m = mw.col.models.byName(notetype)
            # Set note type for deck
            deck = mw.col.decks.get(did)
            deck['mid'] = m['id']
            mw.col.decks.save(deck)
            # Import into the collection
            ti = TextImporter(mw.col, filename)
            ti.allowHTML = True
            ti.initMapping()
            ti.run()

    showInfo("Import complete")
def import_data():
    mw.progress.start(immediate=True)
    mw.checkpoint(_("Importing..."))
    txt = ''
    url = GOOGLE_SHEETS_URL
    response = urllib2.urlopen(url)
    data = csv.reader(response)

    for entry in data:
        deck_name, doc_title, import_flag, doc_url = entry
        # Exclude header
        if (deck_name == 'Deck Name') or (import_flag == 'FALSE'):
            continue

        # Update progress
        mw.checkpoint(_("Importing " + str(deck_name)))

        request = urllib2.urlopen(doc_url)
        soup = BeautifulSoup(request)
        # remove scripts
        for script in soup.findAll('script'):
            script.extract()
        # showText(unicode(soup))
        # inline_unicode_html = pynliner.fromString(str(soup))
        inline_html = ClaSS2Style(unicode(soup)).transform()

        # #replace undesirable style that hides bullet points
        # undesirable = "list-style-type:none"
        # cleaned_inline_html = string.replace(inline_unicode_html, undesirable , "")

        # clean html stling
        inline_soup = BeautifulSoup(inline_html)
        # showText(unicode(inline_soup))
        output = parse_html(inline_soup)

        if output.find("\t") == -1:
            # runs if there are no card rows detected for importing
            continue

        # Write media to collection, write output to temp file
        output = write_img_to_media_col(output, doc_url)
        temp_html_path = write_output_to_html_file(output)

        # select deck by name
        deck_id = mw.col.decks.id(deck_name)
        mw.col.decks.select(deck_id)

        # set model id
        model = mw.col.models.byName("Basic")
        deck = mw.col.decks.get(deck_id)
        deck['mid'] = model['id']
        mw.col.decks.save(deck)

        # import into the collection

        ti = TextImporter(mw.col, temp_html_path)
        ti.delimiter = '\t'
        ti.allowHTML = True
        ti.importMode = 2
        mw.pm.profile['importMode'] = 2

        # #check if deck model and TextImporter model matches
        if deck_id != ti.model['did']:
            ti.model['did'] = deck_id
            mw.col.models.save(ti.model)
        # run text importer
        ti.initMapping()
        ti.run()
        txt += "Import Complete for " + deck_name + ".\n"
        if ti.log:
            # manipulate log to show only necessary fields

            for i in ti.log:
                if i.find("added") != -1:
                    txt += i + "\n\n"
            # txt +=  "".join(ti.log) + "\n"

        # Cleanup
        os.remove(temp_html_path)
        temp_dir = os.path.dirname(temp_html_path)
        os.rmdir(temp_dir)
        mw.col.save()
        mw.reset()
    del_log = ''
    del_log += updated_oldest_card_and_remove_new_duplicates()
    del_log += delete_empty_cards()
    txt += del_log
    mw.progress.finish()
    showText(txt)

    mw.reset()
Beispiel #28
0
def do_import_notes(bcol,
                    deck_name,
                    data_file,
                    note_type,
                    delimiter="\t",
                    import_mode=0):
    col = bcol.col

    existingNotes = {}

    #load existing notes
    bdeck = None
    for dummy, bdk in sorted(bcol.bdecks.items()):
        if deck_name == bdk.name:
            bdeck = bdk
    assert bdeck
    notes = bdeck.queryNotes()
    for n in notes:
        note_id, note_subject, note_content, note_tags = n
        note_content = note_content.split("\x1f")[1]
        note_tags = note_tags.strip()
        existingNotes[note_subject] = [
            note_id, note_subject, note_content, note_tags
        ]

    nochangeNotes = {}
    toBeImportNotes = {}
    toBeUpdatedNotes = {}
    #load data fiel
    fp = open(data_file, "r")
    for line in fp.readlines():
        line = line.strip()
        parts = line.split("\t")
        subject = parts[0]
        content = parts[1]
        if len(content) > int(131072 * 0.8):  #131072 is limit of ANKI field
            logging.error("Content too long to import: %d, note: %s",
                          len(content), subject)
            sys.exit(1)
        if len(parts) == 3:
            tags = parts[2]
            tags = tags.strip()
        else:
            tags = ""
        if subject in existingNotes:
            #compare content and tags
            exist_note = existingNotes[subject]
            if content == exist_note[2] and tags == exist_note[3]:
                #doesn't need to be updated
                nochangeNotes[subject] = True
                pass
            else:
                logging.info("Updated note: %s", subject)
                toBeUpdatedNotes[subject] = [
                    subject, content, tags, exist_note[0]
                ]
        else:
            logging.info("New note: %s", subject)
            toBeImportNotes[subject] = [subject, content, tags]
    fp.close()

    logging.info("%d notes wll be kept without any change", len(nochangeNotes))
    logging.info("%d notes need to be updated.", len(toBeUpdatedNotes))
    logging.info("%d notes need to be added.", len(toBeImportNotes))

    if not toBeUpdatedNotes and not toBeImportNotes:
        col.close()
        logging.info("No new note need to be imported! Bye!")
        sys.exit(1)

    new_data_file = filter_import_data_file(data_file, toBeImportNotes,
                                            toBeUpdatedNotes)
    assert new_data_file

    #set current model
    logging.info("setting current deck name: %s", deck_name)
    deck_id = col.decks.id(deck_name)
    logging.info("setting current deck id: %s", deck_id)
    logging.info("setting note_type : %s", note_type)
    model = col.models.byName(note_type)

    #select deck
    col.decks.select(deck_id)

    #update deck
    deck = col.decks.get(deck_id)
    deck['mid'] = model['id']
    col.decks.save(deck)

    #update model
    model['did'] = deck_id
    col.models.save(model)
    col.models.setCurrent(model)

    logging.info("directly import: %s", new_data_file)
    ti = TextImporter(col, new_data_file)
    ti.allowHTML = True
    ti.needDelimiter = True
    ti.delimiter = "\t"
    ti.importMode = import_mode  #0, UPDATE_MODE; 1, IGNORE_MODE; 2, ADD_MODE
    ti.initMapping()
    ti.run()

    col.save()
    col.close()

    logging.info("Total %d imported,%d updated successfully." %
                 (len(toBeImportNotes), len(toBeUpdatedNotes)))

    return