In [2]:
from glob import glob
import os
import sh
In [3]:
def get_target():
zips_1 = glob('RawDictionary/StarDict/*/*.zip')
zips_2 = glob('RawDictionary/StarDict/*/*.ZIP')
zips = zips_2+zips_1
return zips
def cmd_ops(zip_stardict):
sh.unzip(zip_stardict)
In [4]:
zips = get_target()
In [5]:
zips
Out[5]:
In [7]:
log = sh.unzip(zips[0])
In [8]:
log
Out[8]:
In [9]:
from zipfile import ZipFile
folder, zipfile = os.path.split(zips[0])
zip_ref = ZipFile(zips[0], 'r')
zip_ref.extractall(folder)
zip_ref.close()
In [10]:
folder,zipfile
Out[10]:
In [43]:
import re
In [48]:
re.split(r'.zip',zipfile, maxsplit=10,flags=re.IGNORECASE)
Out[48]:
In [42]:
c=[x for x in glob(folder+'/*') if os.path.isdir(x) and not 'not use' in x];c
Out[42]:
In [23]:
sample = glob(_[0]+'/*.ifo') + glob(_[0]+'/*.IFO')
In [24]:
sh.python('pyglossary/pyglossary.pyw',sample[0],'xml')
Out[24]:
In [31]:
d=[x for x in glob(c[0]+'/*') if os.path.isdir(x)]
d
Out[31]:
In [32]:
sh.make('-C',d[0])
Out[32]:
In [40]:
a = glob('**/*.dictionary',recursive=True);a
Out[40]:
In [38]:
import shutil
In [41]:
shutil.move(a[0],'CompiledDictionary')
Out[41]:
In [51]:
tempfile.gettempdir()
Out[51]:
In [50]:
import tempfile
In [54]:
def cmd_ops(zip_stardict):
folder, zipfile = os.path.split(zip_stardict)
folder_unzip_to = tempfile.gettempdir()
zip_ref = ZipFile(zip_stardict, 'r')
zip_ref.extractall(folder_unzip_to)
zip_ref.close()
# VolubilisEnTh-2.4.2.zip.ZIP -> VolubilisEnTh-2.4.2
folder_unzip = re.split(r'.zip', zipfile, maxsplit=10, flags=re.IGNORECASE)[0]
folder_in_extracted = os.path.join(folder_unzip_to, folder_unzip)
if os.path.exists(folder_in_extracted):
raise Exception('unzip folder not found')
file_ifo = glob(folder_in_extracted + '/*.ifo') + glob(folder_in_extracted + '/*.IFO')
if len(file_ifo) > 1:
raise Exception('found more than 1 ifo')
elif len(file_ifo) == 0:
raise Exception('no ifp file found')
# convert using pyglossary
sh.python('pyglossary/pyglossary.pyw', file_ifo, 'xml')
# VolubilisEnTh-2.4.2 -> VolubilisEnTh
folder_converted = re.split(r'-',folder_unzip,maxsplit=10)[0]
path_make = os.path.join(folder_in_extracted,folder_converted)
sh.make('-C', path_make)
compiledDict = glob(folder_unzip_to + '/**/*.dictionary', recursive=True)
shutil.move(compiledDict, 'CompiledDictionary')
In [55]:
cmd_ops(zips[6])
In [56]:
folder_in_extracted = os.path.join(folder_unzip_to, folder_unzip)
In [58]:
sh.python('pyglossary/pyglossary.pyw', r'/private/var/folders/89/0z3my29s2j5039v_x3nbl5140000gn/T/PlantsThEn-2.4.2/PlantsThEn.ifo', 'xml')
Out[58]:
In [59]:
_
Out[59]:
In [61]:
sh.which('python')
Out[61]:
In [66]:
plist_info = glob('CompiledDictionary/**/Info.plist',recursive=True)
In [65]:
import plistlib as plist
In [73]:
with open(plist_info[0],mode='rb') as file:
a = plist.load(file)
In [74]:
a
Out[74]:
In [79]:
a['DCSDictionaryManufacturerName'] = 'Codustry Laboratory'
In [84]:
ORIGIN_URL = 'https://sites.google.com/site/thaidictproject/'
a['DCSDictionaryCopyright'] = a['CFBundleDisplayName'] + "<br>this original dictionary is from {}<br>Developed Jun 2017 by {}<br>".format(
ORIGIN_URL,
a['DCSDictionaryManufacturerName'] + ': Potchana Project.'
)
a['DCSDictionaryCopyright']
Out[84]:
In [ ]: