Пример #1
0
def main():
    reload(sys)
    sys.setdefaultencoding("utf-8")

    config.prepare()
    try:
        options, args = getopt.getopt(sys.argv[1:], 'anld:cvs:y', ['help'])
    except getopt.GetoptError:
        options = [('--help', '')]
    if ('--help', '') in options:
        show_help()
        return

    use_api = False
    use_db = True
    play_voice = False
    use_dict = True
    for opt in options:
        if opt[0] == '-a':
            use_api = True
        elif opt[0] == '-n':
            use_db = False
        elif opt[0] == '-l':
            show_db_list()
            sys.exit()
        elif opt[0] == '-d':
            del_word(opt[1])
            sys.exit()
        elif opt[0] == '-c':
            del_word(None)
            sys.exit()
        elif opt[0] == '-v':
            play_voice = True
        elif opt[0] == '-s':
            if os.path.isdir(opt[1]):
                print u'stardict 路径设置成功:', opt[1]
                config.set_dict_path(opt[1])
            else:
                print u'stardict 路径设置失败. 原因可能是路径"%s"不存在.' % opt[1]
            sys.exit()
        elif opt[0] == '-y':
            use_dict = False
            use_db = False

    SNAP = os.environ['SNAP']
    print "SNAP: " + SNAP
    config.set_dict_path(SNAP + "/dicts")

    # keyword = unicode(' '.join(args), encoding=sys.getfilesystemencoding())
    keyword = unicode(' '.join(args), encoding='utf-8')

    if not keyword:
        if play_voice:
            word = Word.get_last_word()
            keyword = word.keyword
            query(keyword, play_voice=True, use_db=True)
        else:
            show_help()
    else:
        query(keyword, use_db, use_api, play_voice, use_dict)
Пример #2
0
def main():
    config.prepare()
    try:
        options, args = getopt.getopt(sys.argv[1:], 'anld:cvs:yb:', ['help'])
    except getopt.GetoptError:
        options = [('--help', '')]
    if ('--help', '') in options:
        show_help()
        return

    use_api = False
    use_db = True
    play_voice = False
    use_dict = True
    for opt in options:
        if opt[0] == '-a':
            use_api = True
        elif opt[0] == '-n':
            use_db = False
        elif opt[0] == '-l':
            show_db_list()
            sys.exit()
        elif opt[0] == '-d':
            del_word(opt[1])
            sys.exit()
        elif opt[0] == '-c':
            del_word(None)
            sys.exit()
        elif opt[0] == '-v':
            play_voice = True
        elif opt[0] == '-s':
            print u'stardict 路径设置成功:', opt[1]
            config.set_dict_path(opt[1])
            sys.exit()
        elif opt[0] == '-y':
            use_dict = False
            use_db = False
        elif opt[0] == '-b':
            batch(opt[1], args)
            sys.exit()

    keyword = unicode(' '.join(args), encoding=sys.getfilesystemencoding())

    if not keyword:
        if play_voice:
            word = Word.get_last_word()
            keyword = word.keyword
            query(keyword, play_voice=True, use_db=True)
        else:
            show_help()
    else:
        query(keyword, use_db, use_api, play_voice, use_dict)
Пример #3
0
def main():
    config.prepare()
    try:
        options, args = getopt.getopt(sys.argv[1:], "anld:cvs:y", ["help"])
    except getopt.GetoptError:
        options = [("--help", "")]
    if ("--help", "") in options:
        show_help()
        return

    use_api = False
    use_db = True
    play_voice = False
    use_dict = True
    for opt in options:
        if opt[0] == "-a":
            use_api = True
        elif opt[0] == "-n":
            use_db = False
        elif opt[0] == "-l":
            show_db_list()
            sys.exit()
        elif opt[0] == "-d":
            del_word(opt[1])
            sys.exit()
        elif opt[0] == "-c":
            del_word(None)
            sys.exit()
        elif opt[0] == "-v":
            play_voice = True
        elif opt[0] == "-s":
            print u"stardict 路径设置成功:", opt[1]
            config.set_dict_path(opt[1])
            sys.exit()
        elif opt[0] == "-y":
            use_dict = False
            use_db = False

    keyword = unicode(" ".join(args), encoding=sys.getfilesystemencoding())

    if not keyword:
        if play_voice:
            word = Word.get_last_word()
            keyword = word.keyword
            query(keyword, play_voice=True, use_db=True)
        else:
            show_help()
    else:
        query(keyword, use_db, use_api, play_voice, use_dict)
Пример #4
0
def main():
    # resolve issue #9
    reload(sys)
    sys.setdefaultencoding('utf-8')
    args = parse_args()
    config.prepare()

    if args.stardict:
        if os.path.isdir(args.stardict):
            config.set_dict_path(args.stardict)
            print('stardict 路径设置成功:{}'.format(args.stardict))
        else:
            print('stardict 路径设置失败. 路径"%s"不存在.'.format(args.stardict))
        return

    if args.list:
        show_db_list()
        return

    if args.clean:
        del_word(None)
        return

    if len(args.word) > 0:
        keyword = unicode(' '.join(args.word),
                          encoding=sys.getfilesystemencoding())
    else:
        word = Word.get_last_word()
        keyword = word.keyword

    if args.delete:
        del_word(keyword)
        return

    use_db = not args.new
    use_dict = not args.youdao
    play_voice = args.voice
    query(keyword, use_db, use_dict, play_voice)
Пример #5
0
def main():
    reload(sys)

    config.prepare()
    try:
        # print(sys.argv[1:])
        options, args = getopt.getopt(sys.argv[1:], 'aenfjkl:t:d:cvs:y',
                                      ['help', 'l'])
        # print(sys.argv, options, args)
    except getopt.GetoptError:
        # print("------")
        options = [('--help', '')]

    if ('--help', '') in options:
        # print("------")
        show_help()
        return

    use_api = False
    use_db = True
    play_voice = False
    use_dict = True
    open_ee = False
    to_lang = 'en'

    # print(options)
    for opt in options:
        if opt[0] == '-a':
            use_api = True
        if opt[0] == '-e':
            open_ee = True
        elif opt[0] == '-n':
            use_db = False
        elif opt[0] == '--l':
            show_db_list()
            sys.exit()
        elif opt[0] == '-l':
            show_today_list(opt[1])
            sys.exit()
        elif opt[0] == '-t':
            to_lang = opt[1]
        elif opt[0] == '-d':
            del_word(opt[1])
            sys.exit()
        elif opt[0] == '-c':
            del_word(None)
            sys.exit()
        elif opt[0] == '-v':
            play_voice = True
        elif opt[0] == '-s':
            if os.path.isdir(opt[1]):
                print(u'stardict 路径设置成功:', opt[1])
                config.set_dict_path(opt[1])
            else:
                print(u'stardict 路径设置失败. 原因可能是路径"%s"不存在.' % opt[1])
            sys.exit()
        elif opt[0] == '-y':
            use_dict = False
            use_db = False
        else:
            print(opt)

    # print(options, args)
    dict_path = os.path.join(config.HOME, "dicts")
    config.set_dict_path(dict_path)

    # keyword = unicode(' '.join(args), encoding=sys.getfilesystemencoding())
    # keyword = unicode(' '.join(args), encoding='utf-8')
    keyword = ' '.join(args)
    # print(keyword, to_lang, args)

    if not keyword:
        if play_voice:
            word = Word.get_last_word()
            keyword = word.keyword
            query(keyword, play_voice=True, use_db=True, to_lang=to_lang)
        else:
            show_help()
    else:
        query(keyword, use_db, use_api, play_voice, use_dict, open_ee, to_lang)