Created
August 24, 2023 17:54
-
-
Save aso2101/cd34dea18653db34a76bf8176a0f1b2c to your computer and use it in GitHub Desktop.
transliterator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import sanscript | |
from os.path import abspath | |
from os.path import splitext | |
from os.path import basename | |
import sys | |
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description="Convert a file from one script to another using Sanscript and print the output to stdout.\n\nAvailable scripts are: bengali, devanagari, gujarati, gurmukhi, kannada, malayalam, oriya, tamil, telugu, hk, iast, iso, itrans, kolkata, slp1, velthuis, wx.") | |
parser.add_argument("filename",nargs="+",type=str,help="The input file") | |
parser.add_argument("fr",nargs="+",type=str,help="The input script") | |
parser.add_argument("to",nargs="+",type=str,help="The output script") | |
args = parser.parse_args() | |
out = open(splitext(basename(args.filename[0]))[0] + "-" + args.to[0] + ".txt",'w') | |
with open(abspath(args.filename[0]), 'r') as textfile: | |
text = textfile.readlines() | |
for i in range(len(text)): | |
x = text[i] | |
out.write(sanscript.transliterate(x,args.fr[0],args.to[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment