Skip to content

Commit

Permalink
feat: release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Larify committed May 18, 2021
1 parent ccda7a1 commit c3214e1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
Binary file not shown.
23 changes: 23 additions & 0 deletions src/i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-

import os

langs = {
'en_US' : {
"DEFAULT_TITLE" : u'Search word',
"DEFAULT_SUBTITLE" : u'Please input a english word.',
"DEFAULT_ERROR" : u'Word not found.'
},
'zh_CN' : {
"DEFAULT_TITLE" : u'爱词霸查词',
"DEFAULT_SUBTITLE" : u'请输入需要查询的英文单词',
"DEFAULT_ERROR" : u'没有查到单词的释义'
}
}

local = os.popen('defaults read -g AppleLocale').read().rstrip()

try:
dic = langs[local]
except KeyError as e:
dic = langs['zh_CN']
28 changes: 20 additions & 8 deletions src/iciba.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
import time

from workflow import Workflow3, web
import i18n

reload(sys)
sys.setdefaultencoding('utf-8')

def fail_feedback():
wf.add_item(title=i18n.dic["DEFAULT_TITLE"], subtitle=i18n.dic["DEFAULT_ERROR"], icon="icon.png")
wf.send_feedback()

def iciba_search(word):
now = int(round(time.time() * 1000))
hash_key = '7ece94d9f9c202b0d2ec557dg4r9bc'
Expand All @@ -22,22 +27,29 @@ def iciba_search(word):
query ={'client': '6', 'key': '1000006', 'timestamp': now, 'word': word, 'signature': signature}
url = "https://dict.iciba.com/dictionary/word/query/web?%s" % urllib.urlencode(query)
r = web.get(url).json()
for dic in r["message"]["baesInfo"]["symbols"][0]["parts"]:
wf.add_item(";".join(dic["means"]), dic["part"], icon="icon.png", valid=True, arg=word)
wf.send_feedback()

wf.logger.info("request url: %s" % url)
if ("symbols" in r["message"]["baesInfo"]):
for dic in r["message"]["baesInfo"]["symbols"][0]["parts"]:
wf.add_item(title=";".join(dic["means"]), subtitle=dic["part"], icon="icon.png", valid=True, arg=word)
wf.send_feedback()
elif ("translate_result" in r["message"]["baesInfo"]):
baseInfo = r["message"]["baesInfo"]
wf.add_item(title=baseInfo["translate_result"], subtitle=baseInfo["translate_msg"], icon="icon.png", valid=True, arg=word)
wf.send_feedback()
else:
fail_feedback()

def main(wf):
try:
if len(wf.args) > 0:
word = wf.args[0]
word = ' '.join(wf.args[0:])
wf.logger.info("translate word: %s" % word)
iciba_search(word)
else:
wf.add_item('爱词霸查词', '请输入需要查询的英文单词', icon="icon.png")
wf.send_feedback()
fail_feedback()
except:
wf.logger.error(sys.exc_info()[0])
wf.send_feedback()
fail_feedback()

if __name__ == '__main__':
wf = Workflow3()
Expand Down

0 comments on commit c3214e1

Please sign in to comment.