-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.py
44 lines (32 loc) · 1000 Bytes
/
query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
import json
import sys
from workflow import web, Workflow3
reload(sys)
sys.setdefaultencoding('utf-8')
def main(wf=Workflow3()):
queryStr = wf.args[0].strip()
result = queryTrans(queryStr)
for word in result:
wf.add_item(word)
if len(result) == 0:
wf.add_item(u'未查询到该缩写的翻译')
wf.send_feedback()
def queryTrans(queryStr):
data = json.dumps({'text': queryStr})
res = web.post('https://lab.magiconch.com/api/nbnhhsh/guess'
, headers={'content-type': 'application/json'}
, data=str(data)
)
if res.status_code != 200:
return [u"错误" + res.status_code]
resJson = res.json()
if len(resJson) == 0:
return []
if 'trans' in resJson[0]:
return resJson[0]['trans']
if 'inputting' in resJson[0]:
return resJson[0]['inputting']
if __name__ == '__main__':
wf = Workflow3()
sys.exit(wf.run(main))