return cache options = config['options'] if config else {} dict_name = cndict.get_full_name(dictionary) options = options.get(dict_name, {}) result = cndict.lookup(dictionary, word, **options) if result: result = [item.decode('utf-8') for item in result] if enable_cache: dict_cache.set(cache_name, result, cache_expire) return result feedback = Feedback() plist = AlfredPlist() plist.read(os.path.abspath('./info.plist')) base_dir = os.path.expanduser('~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/') dict_cache = Cache(os.path.join(base_dir, plist.get_bundleid())) try: config_data = open(os.path.abspath('./config.json')).read() config = json.loads(re.sub(r'//.*', '', config_data)) except: config = {} sys.argv = [arg for arg in sys.argv if arg != ''] argc = len(sys.argv) if argc == 1: feedback.add_item(title=u'Dict - Lookup Word', subtitle=u'Format: "word @ dict". Available dicts are "nj", "ld", "yd", "cb", "bd", "by", "hc".',
def restore(arg): os.system( """osascript -e 'tell application "Alfred 2" to search "{}"' &""". format(arg.replace('"', '\\"'))) def shell_exec(cmd, arg, escape=False): if escape: arg = arg.replace("%", "%%").replace("\\", "\\\\") os.environ['LANG'] = 'en_US.UTF-8' os.system(cmd.format("'{}'".format(arg.replace("'", "\\'")))) plist = AlfredPlist() plist.read(os.path.abspath('./info.plist')) match = re.match(r'^:(.*?) ([@|>]) (.*?)$', sys.argv[1]) if match: command = match.group(1).strip() if command == 'clean': base_dir = os.path.expanduser( '~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/') dict_cache = Cache(os.path.join(base_dir, plist.get_bundleid())) dict_cache.clean() print 'Cache has been cleaned.' elif command == 'config': shell_exec('open {}', os.path.abspath('./config.json')) print 'Please edit config file in your editor.' elif command == 'update':
return cache options = config['options'] if config else {} dict_name = cndict.get_full_name(dictionary) options = options.get(dict_name, {}) result = cndict.lookup(dictionary, word, **options) if result: result = [item.decode('utf-8') for item in result] if enable_cache: dict_cache.set(cache_name, result, cache_expire) return result feedback = Feedback() plist = AlfredPlist() plist.read(os.path.abspath('./info.plist')) base_dir = os.path.expanduser( '~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/') dict_cache = Cache(os.path.join(base_dir, plist.get_bundleid())) try: config_data = open(os.path.abspath('./config.json')).read() config = json.loads(re.sub(r'//.*', '', config_data)) except: config = {} sys.argv = [arg for arg in sys.argv if arg != ''] argc = len(sys.argv) if argc == 1: feedback.add_item(
if len(sys.argv) != 2: sys.exit(1) def restore(arg): os.system("""osascript -e 'tell application "Alfred 2" to search "{}"' &""".format(arg.replace('"', '\\"'))) def shell_exec(cmd, arg, escape=False): if escape: arg = arg.replace("%", "%%").replace("\\", "\\\\") os.environ['LANG'] = 'en_US.UTF-8' os.system(cmd.format("'{}'".format(arg.replace("'", "\\'")))) plist = AlfredPlist() plist.read(os.path.abspath('./info.plist')) match = re.match(r'^:(.*?) ([@|>]) (.*?)$', sys.argv[1]) if match: command = match.group(1).strip() if command == 'clean': base_dir = os.path.expanduser('~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/') dict_cache = Cache(os.path.join(base_dir, plist.get_bundleid())) dict_cache.clean() print 'Cache has been cleaned.' elif command == 'config': shell_exec('open {}', os.path.abspath('./config.json')) print 'Please edit config file in your editor.' elif command == 'update': config_data = open(os.path.abspath('./config.json')).read()