from variables import getDictBooksJsPath from variables import getSuccinctTrieJsonPath from variables import getSuccinctTrieJsPath def toAngularJSModule(jsonPath, jsPath): with open(jsPath, 'w') as f: f.write("angular.module('pali.dicBooks', []).\n") f.write(" factory('dicBooks', [function() {\n") f.write(" return { dicIndex: ") with open(jsonPath, 'r') as f2: f.write(f2.read()) f.write(" };\n") f.write(" }]);\n") def toAngularJSModule2(jsonPath, jsPath): with open(jsPath, 'w') as f: f.write("angular.module('pali.succinctTrie', []).\n") f.write(" factory('succinctTrie', [function() {\n") f.write(" return { data: ") with open(jsonPath, 'r') as f2: f.write(f2.read()) f.write(" };\n") f.write(" }]);\n") if __name__ == '__main__': toAngularJSModule(getDictBooksJsonPath(), getDictBooksJsPath()) toAngularJSModule2(getSuccinctTrieJsonPath(), getSuccinctTrieJsPath())
wordreader = csv.reader(f, delimiter=',', quotechar='"') for row in wordreader: if len(row) != 7: raise Exception('len(row) != 7') if row[0] == 'db_id': continue word = row[4].decode('utf-8').lower() if row[2] == dicId: yield [word, row[6]] if __name__ == '__main__': gs = goslate.Goslate() #print(gs.get_languages()) with open(getDictBooksJsonPath(), 'r') as f: dicIndex = json.loads(f.read()) """ Pali-English Id: "N": "Buddhist Dictionary by NYANATILOKA MAHATHERA" "C": "Concise Pali-English Dictionary by A.P. Buddhadatta Mahathera" "P": "PTS Pali-English dictionary The Pali Text Society's Pali-English dictionary" "V": "Buddhist Dictionary of Pali Proper Names by G P Malalasekera" "I": "Pali-Dictionary Vipassana Research Institute" """ dicId = 'C' outputPath = os.path.join(os.path.dirname(__file__), 'output.csv') tmpPath = os.path.join(os.path.dirname(__file__), 'tmp.csv')
else: data.append([row[2], row[6]]) with open(path, 'w') as f: f.write(json.dumps(data)) else: # create new data file if dicIndex[row[2]][0] == 'zh': # convert simplified chinese to traditional chinese data = [[row[2], jtof(row[6])]] else: data = [[row[2], row[6]]] with open(path, 'w') as f: f.write(json.dumps(data)) if __name__ == '__main__': # read index of dictionary books with open(getDictBooksJsonPath(), 'r') as f: dicIndex = json.loads(f.read()) if os.path.exists(getDictWordsJsonDir()): shutil.rmtree(getDictWordsJsonDir()) os.makedirs(getDictWordsJsonDir()) else: os.makedirs(getDictWordsJsonDir()) processWordCSV(getDictWordsCSV1Path(), dicIndex, getDictWordsJsonDir()) processWordCSV(getDictWordsCSV2Path(), dicIndex, getDictWordsJsonDir())
from variables import getDictBooksJsPath from variables import getSuccinctTrieJsonPath from variables import getSuccinctTrieJsPath def toAngularJSModule(jsonPath, jsPath): with open(jsPath, "w") as f: f.write("angular.module('pali.dicBooks', []).\n") f.write(" factory('dicBooks', [function() {\n") f.write(" return { dicIndex: ") with open(jsonPath, "r") as f2: f.write(f2.read()) f.write(" };\n") f.write(" }]);\n") def toAngularJSModule2(jsonPath, jsPath): with open(jsPath, "w") as f: f.write("angular.module('pali.succinctTrie', []).\n") f.write(" factory('succinctTrie', [function() {\n") f.write(" return { data: ") with open(jsonPath, "r") as f2: f.write(f2.read()) f.write(" };\n") f.write(" }]);\n") if __name__ == "__main__": toAngularJSModule(getDictBooksJsonPath(), getDictBooksJsPath()) toAngularJSModule2(getSuccinctTrieJsonPath(), getSuccinctTrieJsPath())
def writeJsonFile(dicIndex): if not os.path.exists(os.path.dirname(getDictBooksJsonPath())): os.makedirs(os.path.dirname(getDictBooksJsonPath())) with open(getDictBooksJsonPath(), 'w') as f: f.write(json.dumps(dicIndex))