Monday, August 14, 2017

csv file to dict file

*** fromcsvtodict.py
import sys
import csv
import os

inputfile = sys.argv[1]
tempfile = open("tempfile","w")


with open(inputfile) as f:
    csvf = csv.reader(f, delimiter=',', quotechar='\"')

    for i in csvf:
        tempfile.write(i[0])
        tempfile.write("\t")
        tempfile.write(i[1])
        tempfile.write("\n\n")
tempfile.close()

command = "/usr/lib/stardict-tools/tabfile " + "tempfile"


os.system(command)


1- usage

$ python fromcsvtodict.py input.csv

it will generate 3 files
tempfile.dict.dz  tempfile.idx  tempfile.ifo

and to change dictionary name, edit tempfile.ifo and change
bookname=ITC-T REC G-826 or and anything else.


No comments:

Post a Comment