Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def initSphynx(self):
addons = mw.pm.addonFolder()
self.file_language_model = os.path.join(addons,'voice_control','anki.lm')
self.file_dictionary = os.path.join(addons,'voice_control','anki.dic')
self.init_actions()
def installZipFile(data, fname):
base = mw.pm.addonFolder()#os.path.join(defaultBase(),'addons')
if fname.endswith(".py"):
path = os.path.join(base, fname)
with open(path, "wb") as file:
file.write(data)
file.close()
return True
# .zip file
try:
z = zipfile.ZipFile(io.BytesIO(data))
except zipfile.BadZipfile:
return False
for n in z.namelist():
if n.endswith("/"):
# folder; ignore
continue
# write
def defaultBase():
path = mw.pm.addonFolder()
return os.path.dirname(os.path.abspath(path))
from aqt import mw # We need this early to get to the path
# These *are* available with standard Anki
import math
import os
import sys
from anki import utils, sched, stats
from anki.lang import _
# To override fmtTimeSpan that are already loaded:
from aqt import browser, deckbrowser, reviewer
# Now add the path, but only once. (Other add-ons by YT contain
# similar code.)
if not [pe for pe in sys.path if 'batteries' in pe]:
sys.path.append(os.path.join(mw.pm.addonFolder(), "batteries"))
# Now this should work. Include module to deal with numbers digit by
# digit.
from decimal import Decimal
"""Replace time values with just days or years."""
__version__ = "1.0.1"
day_format_separators = {-1: u'.', -3: u"’", -4: u"’", -6: u"’"}
# Year length taken from Wikipedia's tropical year article as "mean
# tropical year current value"
year = 365.2421897
# NIST value for tropical year
# year = 3.155693E+07 / 86400.0
# which is 5.567e-05 days or 4.81s longer
def defaultBase():
path = mw.pm.addonFolder()
return os.path.dirname(os.path.abspath(path))
def getConfigFilePathName(self):
return os.path.join(mw.pm.addonFolder(), 'kol', KolConfig.CONFIGFILENAME)
def __init__(self):
# N.B. This assumes that type is either 'cantonese' or
# 'mandarin'.
readings_file_name = os.path.join(mw.pm.addonFolder(), 'chinese',
type + '_readings.json')
self.readings = json.load(open(readings_file_name))
def __setupObjectData(self):
self.kanjiDefaultDictPath = os.path.join(mw.pm.addonFolder(), "kol", "data", "english.db")
self.kanjiCustomDictPath = os.path.join(mw.pm.profileFolder(), "kol", "user_files", "custom-kol.db")
self.cssFileInPlugin = os.path.join(mw.pm.addonFolder(), "kol", "data", "styles.css")
self.cssFileUserFiles = os.path.join(mw.pm.addonFolder(), "kol", "user_files", "styles.css")
self.scriptsFileInPlugin = os.path.join(mw.pm.addonFolder(), "kol", "data", "scripts.js")
self.scriptsFileUserFiles = os.path.join(mw.pm.addonFolder(), "kol", "user_files", "scripts.js")
self.templateInPlugin = os.path.join(mw.pm.addonFolder(), "kol", "data", "template.hbs")
self.templateUserFiles = os.path.join(mw.pm.addonFolder(), "kol", "user_files", "template.hbs")