remove index param from export.
This commit is contained in:
parent
91f302a769
commit
c40f99856a
@ -1,7 +1,7 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
import re
|
||||
import FastWQ
|
||||
from .base import MdxService, export, register, with_styles, parseHtml
|
||||
from .base import MdxService, export, register, with_styles, parse_html
|
||||
|
||||
PATH = FastWQ.LDOCE6_PATH
|
||||
|
||||
@ -27,7 +27,7 @@ class Ldoce6(MdxService):
|
||||
def title(self):
|
||||
return self.__register_label__
|
||||
|
||||
@export('PHON', 1)
|
||||
@export('PHON')
|
||||
def fld_phonetic(self):
|
||||
html = self.get_html()
|
||||
m = re.search(r'<span class="pron">(.*?)</span>', html)
|
||||
@ -60,19 +60,19 @@ class Ldoce6(MdxService):
|
||||
return self.get_anki_label(name, 'audio')
|
||||
return ''
|
||||
|
||||
@export('BRE_PRON', 2)
|
||||
@export('BRE_PRON')
|
||||
def fld_voicebre(self):
|
||||
return self._fld_voice(self.get_html(), 'br')
|
||||
|
||||
@export('AME_PRON', 3)
|
||||
@export('AME_PRON')
|
||||
def fld_voiceame(self):
|
||||
return self._fld_voice(self.get_html(), 'us')
|
||||
|
||||
@export('EXAMPLE', 4)
|
||||
@export('EXAMPLE')
|
||||
def fld_sentence(self):
|
||||
m = re.findall(r'<span class="example"\s*.*>\s*.*<\/span>', self.get_html())
|
||||
if m:
|
||||
soup = parseHtml(m[0])
|
||||
soup = parse_html(m[0])
|
||||
el_list = soup.findAll('span', {'class':'example'})
|
||||
if el_list:
|
||||
maps = [u''.join(str(content).decode('utf-8') for content in element.contents)
|
||||
@ -85,11 +85,11 @@ class Ldoce6(MdxService):
|
||||
return self._css(my_str)
|
||||
return ''
|
||||
|
||||
@export('DEF', 5)
|
||||
@export('DEF')
|
||||
def fld_definate(self):
|
||||
m = m = re.findall(r'<span class="def"\s*.*>\s*.*<\/span>', self.get_html())
|
||||
if m:
|
||||
soup = parseHtml(m[0])
|
||||
soup = parse_html(m[0])
|
||||
el_list = soup.findAll('span', {'class':'def'})
|
||||
if el_list:
|
||||
maps = [u''.join(str(content).decode('utf-8') for content in element.contents)
|
||||
|
||||
@ -37,7 +37,7 @@ class Baicizhan(WebService):
|
||||
def _get_field(self, key, default=u''):
|
||||
return self.cache_result(key) if self.cached(key) else self._get_from_api().get(key, default)
|
||||
|
||||
@export('PRON', 0)
|
||||
@export('PRON')
|
||||
def fld_phonetic(self):
|
||||
word = self.word.replace(' ', '_')
|
||||
url = u'http://baicizhan.qiniucdn.com/word_audios/{}.mp3'.format(word)
|
||||
@ -58,11 +58,11 @@ class Baicizhan(WebService):
|
||||
else:
|
||||
return url
|
||||
|
||||
@export('PHON', 1)
|
||||
@export('PHON')
|
||||
def fld_phon(self):
|
||||
return self._get_field('accent')
|
||||
|
||||
@export('IMAGE', 2)
|
||||
@export('IMAGE')
|
||||
def fld_img(self):
|
||||
url = self._get_field('img')
|
||||
if url and self.bcz_download_img:
|
||||
@ -72,7 +72,7 @@ class Baicizhan(WebService):
|
||||
#return self.get_anki_label(url, 'img')
|
||||
return ''
|
||||
|
||||
@export([u'象形', u'Pictogram'], 3)
|
||||
@export([u'象形', u'Pictogram'])
|
||||
def fld_df(self):
|
||||
url = self._get_field('df')
|
||||
if url and self.bcz_download_img:
|
||||
@ -82,19 +82,19 @@ class Baicizhan(WebService):
|
||||
#return self.get_anki_label(url, 'img')
|
||||
return ''
|
||||
|
||||
@export(u'DEF', 6)
|
||||
@export(u'DEF')
|
||||
def fld_mean(self):
|
||||
return self._get_field('mean_cn')
|
||||
|
||||
@export(u'EXAMPLE', 4)
|
||||
@export(u'EXAMPLE')
|
||||
def fld_st(self):
|
||||
return self._get_field('st')
|
||||
|
||||
@export('TRANS', 5)
|
||||
@export('TRANS')
|
||||
def fld_sttr(self):
|
||||
return self._get_field('sttr')
|
||||
|
||||
@export([u'单词tv', u'TV'], 7)
|
||||
@export([u'单词tv', u'TV'])
|
||||
def fld_tv_url(self):
|
||||
video = self._get_field('tv')
|
||||
if video:
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
from hashlib import sha1
|
||||
from .base import WebService, export, register, with_styles, parseHtml
|
||||
from .base import WebService, export, register, with_styles, parse_html
|
||||
|
||||
baidu_download_mp3 = True
|
||||
|
||||
@ -13,7 +13,7 @@ class Baidu_Chinese(WebService):
|
||||
def _get_content(self):
|
||||
url = u"http://dict.baidu.com/s?wd={}#basicmean".format(self.word)
|
||||
html = self.get_response(url, timeout=10)
|
||||
soup = parseHtml(html)
|
||||
soup = parse_html(html)
|
||||
result = {
|
||||
'pinyin': '',
|
||||
'basicmean': '',
|
||||
@ -63,11 +63,11 @@ class Baidu_Chinese(WebService):
|
||||
def _css(self, val):
|
||||
return val
|
||||
|
||||
@export([u'拼音', u'Phoneticize'], 1)
|
||||
@export([u'拼音', u'Phoneticize'])
|
||||
def fld_pinyin(self):
|
||||
return self._get_field('pinyin')
|
||||
|
||||
@export('PRON', 2)
|
||||
@export('PRON')
|
||||
def fld_pron(self):
|
||||
audio_url = self._get_field('audio_url')
|
||||
if baidu_download_mp3 and audio_url:
|
||||
@ -96,20 +96,20 @@ class Baidu_Chinese(WebService):
|
||||
pass
|
||||
return ''
|
||||
|
||||
@export([u'基本释义', u'Basic Definitions'], 3)
|
||||
@export([u'基本释义', u'Basic Definitions'])
|
||||
def fld_basic(self):
|
||||
val = self._get_field('basicmean')
|
||||
if val is None or val == '':
|
||||
return ''
|
||||
return self._css(val)
|
||||
|
||||
@export([u'详细释义', u'Detail Definitions'], 4)
|
||||
@export([u'详细释义', u'Detail Definitions'])
|
||||
def fld_detail(self):
|
||||
val = self._get_field('detailmean')
|
||||
if val is None or val == '':
|
||||
return ''
|
||||
return self._css(val)
|
||||
|
||||
@export([u'英文翻译', u'Translation[En]'], 5)
|
||||
@export([u'英文翻译', u'Translation[En]'])
|
||||
def fld_fanyi(self):
|
||||
return self._get_field('fanyi')
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
|
||||
import inspect
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
# use ntpath module to ensure the windows-style (e.g. '\\LDOCE.css')
|
||||
# path can be processed on Unix platform.
|
||||
# However, anki version on mac platforms doesn't including this package?
|
||||
@ -49,28 +51,52 @@ except ImportError:
|
||||
import dummy_threading as _threading
|
||||
|
||||
|
||||
__all__ = [
|
||||
'register', 'export', 'copy_static_file', 'with_styles', 'parse_html', 'service_wrap',
|
||||
'Service', 'WebService', 'LocalService', 'MdxService', 'StardictService', 'QueryResult'
|
||||
]
|
||||
|
||||
|
||||
def register(labels):
|
||||
"""
|
||||
register the dict service with a labels, which will be shown in the dicts list.
|
||||
"""
|
||||
def _deco(cls):
|
||||
cls.__register_label__ = _cl(labels)
|
||||
|
||||
methods = inspect.getmembers(cls, predicate=inspect.ismethod)
|
||||
exports = []
|
||||
for method in methods:
|
||||
attrs = getattr(method[1], '__export_attrs__', None)
|
||||
if attrs and attrs[1] == -1:
|
||||
exports.append((
|
||||
getattr(method[1], '__def_index__', 0),
|
||||
method[1]
|
||||
))
|
||||
exports = sorted(exports)
|
||||
for index, method in enumerate(exports):
|
||||
attrs = getattr(method[1], '__export_attrs__', None)
|
||||
attrs[1] = index
|
||||
|
||||
return cls
|
||||
return _deco
|
||||
|
||||
|
||||
def export(labels, index):
|
||||
def export(labels):
|
||||
"""
|
||||
export dict field function with a labels, which will be shown in the fields list.
|
||||
"""
|
||||
def _with(fld_func):
|
||||
@wraps(fld_func)
|
||||
def _deco(cls, *args, **kwargs):
|
||||
res = fld_func(cls, *args, **kwargs)
|
||||
def _deco(self, *args, **kwargs):
|
||||
res = fld_func(self, *args, **kwargs)
|
||||
return QueryResult(result=res) if not isinstance(res, QueryResult) else res
|
||||
_deco.__export_attrs__ = (_cl(labels), index)
|
||||
_deco.__export_attrs__ = [_cl(labels), -1]
|
||||
_deco.__def_index__ = export.EXPORT_INDEX
|
||||
export.EXPORT_INDEX += 1
|
||||
return _deco
|
||||
return _with
|
||||
export.EXPORT_INDEX = 0
|
||||
|
||||
|
||||
def copy_static_file(filename, new_filename=None, static_dir='static'):
|
||||
@ -132,13 +158,13 @@ def with_styles(**styles):
|
||||
return _with
|
||||
|
||||
# bs4 threading lock, overload protection
|
||||
BS_LOCKS = [_threading.Lock(), _threading.Lock()]
|
||||
_BS_LOCKS = [_threading.Lock(), _threading.Lock()]
|
||||
|
||||
def parseHtml(html):
|
||||
def parse_html(html):
|
||||
'''
|
||||
use bs4 lib parse HTML, run only 2 BS at the same time
|
||||
'''
|
||||
lock = BS_LOCKS[random.randrange(0, len(BS_LOCKS) - 1, 1)]
|
||||
lock = _BS_LOCKS[random.randrange(0, len(_BS_LOCKS) - 1, 1)]
|
||||
lock.acquire()
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
lock.release()
|
||||
@ -161,7 +187,7 @@ class Service(object):
|
||||
|
||||
def __init__(self):
|
||||
self.cache = defaultdict(defaultdict)
|
||||
self._exporters = self.get_exporters()
|
||||
self._exporters = self._get_exporters()
|
||||
self._fields, self._actions = zip(*self._exporters) \
|
||||
if self._exporters else (None, None)
|
||||
# query interval: default 500ms
|
||||
@ -193,28 +219,21 @@ class Service(object):
|
||||
def exporters(self):
|
||||
return self._exporters
|
||||
|
||||
def get_exporters(self):
|
||||
def _get_exporters(self):
|
||||
flds = dict()
|
||||
methods = inspect.getmembers(self, predicate=inspect.ismethod)
|
||||
for method in methods:
|
||||
export_attrs = getattr(method[1], '__export_attrs__', None)
|
||||
if export_attrs:
|
||||
label, index = export_attrs
|
||||
label, index = export_attrs[0], export_attrs[1]
|
||||
flds.update({int(index): (label, method[1])})
|
||||
sorted_flds = sorted(flds)
|
||||
return [flds[key] for key in sorted_flds]
|
||||
|
||||
def active(self, action_label, word):
|
||||
def active(self, fld_ord, word):
|
||||
self.word = word
|
||||
# if the service instance is LocalService,
|
||||
# then have to build then index.
|
||||
#if isinstance(self, LocalService):
|
||||
# if isinstance(self, MdxService) or isinstance(self, StardictService):
|
||||
# self.builder.check_build()
|
||||
|
||||
for each in self.exporters:
|
||||
if action_label == each[0]:
|
||||
return each[1]()
|
||||
if fld_ord >= 0 and fld_ord < len(self.actions):
|
||||
return self.actions[fld_ord]()
|
||||
return QueryResult.default()
|
||||
|
||||
@staticmethod
|
||||
@ -468,9 +487,9 @@ class LocalService(Service):
|
||||
def _filename(self):
|
||||
return os.path.splitext(os.path.basename(self.dict_path))[0]
|
||||
|
||||
def active(self, action_label, word):
|
||||
def active(self, fld_ord, word):
|
||||
self.missed_css.clear()
|
||||
return super(LocalService, self).active(action_label, word)
|
||||
return super(LocalService, self).active(fld_ord, word)
|
||||
|
||||
|
||||
class MdxService(LocalService):
|
||||
@ -503,7 +522,7 @@ class MdxService(LocalService):
|
||||
else:
|
||||
return self.builder._title
|
||||
|
||||
@export([u'默认', u'Default'], 0)
|
||||
@export([u'默认', u'Default'])
|
||||
def fld_whole(self):
|
||||
html = self.get_default_html()
|
||||
js = re.findall(r'<script.*?>.*?</script>', html, re.DOTALL)
|
||||
@ -650,7 +669,9 @@ class MdxService(LocalService):
|
||||
|
||||
|
||||
class StardictService(LocalService):
|
||||
|
||||
'''
|
||||
Stardict Local Dictionary Service
|
||||
'''
|
||||
def __init__(self, dict_path):
|
||||
super(StardictService, self).__init__(dict_path)
|
||||
self.query_interval = 0.05
|
||||
@ -677,7 +698,7 @@ class StardictService(LocalService):
|
||||
else:
|
||||
return self.builder.ifo.bookname.decode('utf-8')
|
||||
|
||||
@export([u'默认', u'Default'], 0)
|
||||
@export([u'默认', u'Default'])
|
||||
def fld_whole(self):
|
||||
#self.builder.check_build()
|
||||
try:
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#-*- coding:utf-8 -*-
|
||||
import re
|
||||
from .base import WebService, export, register, with_styles, parseHtml
|
||||
from .base import WebService, export, register, with_styles, parse_html
|
||||
|
||||
bing_download_mp3 = True
|
||||
|
||||
@ -13,7 +13,7 @@ class Bing(WebService):
|
||||
def _get_content(self):
|
||||
word = self.word.replace(' ', '_')
|
||||
data = self.get_response(u"http://cn.bing.com/dict/search?q={}&mkt=zh-cn".format(word))
|
||||
soup = parseHtml(data)
|
||||
soup = parse_html(data)
|
||||
result = {
|
||||
'pronunciation': {'AmE': '', 'BrE': '', 'AmEmp3': '', 'BrEmp3': ''},
|
||||
'def': '',
|
||||
@ -73,12 +73,12 @@ class Bing(WebService):
|
||||
def _css(self, val):
|
||||
return val
|
||||
|
||||
@export('AME_PHON', 1)
|
||||
@export('AME_PHON')
|
||||
def fld_phonetic_us(self):
|
||||
seg = self._get_field('pronunciation')
|
||||
return seg.get('AmE', u'')
|
||||
|
||||
@export('BRE_PHON', 2)
|
||||
@export('BRE_PHON')
|
||||
def fld_phonetic_uk(self):
|
||||
seg = self._get_field('pronunciation')
|
||||
return seg.get('BrE', u'')
|
||||
@ -91,22 +91,22 @@ class Bing(WebService):
|
||||
return self.get_anki_label(filename, 'audio')
|
||||
return ''
|
||||
|
||||
@export('AME_PRON', 3)
|
||||
@export('AME_PRON')
|
||||
def fld_mp3_us(self):
|
||||
return self._fld_mp3('AmEmp3')
|
||||
|
||||
@export('BRE_PRON', 4)
|
||||
@export('BRE_PRON')
|
||||
def fld_mp3_uk(self):
|
||||
return self._fld_mp3('BrEmp3')
|
||||
|
||||
@export('DEF', 5)
|
||||
@export('DEF')
|
||||
def fld_definition(self):
|
||||
val = self._get_field('def')
|
||||
if val == None or val == '':
|
||||
return ''
|
||||
return self._css(val)
|
||||
|
||||
@export('EXAMPLE', 6)
|
||||
@export('EXAMPLE')
|
||||
def fld_samples(self):
|
||||
max_numbers = 10
|
||||
segs = self._get_field('sams')
|
||||
|
||||
@ -32,12 +32,12 @@ class BingXtk(WebService):
|
||||
def _get_field(self, key, default=u''):
|
||||
return self.cache_result(key) if self.cached(key) else self._get_content().get(key, default)
|
||||
|
||||
@export('AME_PHON', 1)
|
||||
@export('AME_PHON')
|
||||
def fld_phonetic_us(self):
|
||||
seg = self._get_field('pronunciation')
|
||||
return seg.get('AmE', u'')
|
||||
|
||||
@export('BRE_PHON', 2)
|
||||
@export('BRE_PHON')
|
||||
def fld_phonetic_uk(self):
|
||||
seg = self._get_field('pronunciation')
|
||||
return seg.get('BrE', u'')
|
||||
@ -50,11 +50,11 @@ class BingXtk(WebService):
|
||||
return self.get_anki_label(filename, 'audio')
|
||||
return ''
|
||||
|
||||
@export('AME_PRON', 3)
|
||||
@export('AME_PRON')
|
||||
def fld_mp3_us(self):
|
||||
return self._fld_mp3('AmEmp3')
|
||||
|
||||
@export('BRE_PRON', 4)
|
||||
@export('BRE_PRON')
|
||||
def fld_mp3_uk(self):
|
||||
return self._fld_mp3('BrEmp3')
|
||||
|
||||
@ -62,7 +62,7 @@ class BingXtk(WebService):
|
||||
def _css(self, val):
|
||||
return val
|
||||
|
||||
@export('DEF', 5)
|
||||
@export('DEF')
|
||||
def fld_definition(self):
|
||||
segs = self._get_field('defs')
|
||||
if isinstance(segs, list) and len(segs) > 0:
|
||||
@ -71,7 +71,7 @@ class BingXtk(WebService):
|
||||
return self._css(val)
|
||||
return ''
|
||||
|
||||
@export('EXAMPLE', 6)
|
||||
@export('EXAMPLE')
|
||||
def fld_samples(self):
|
||||
max_numbers = 10
|
||||
segs = self._get_field('sams')
|
||||
|
||||
@ -65,7 +65,7 @@ class Esdict(WebService):
|
||||
def _get_field(self, key, default=u''):
|
||||
return self.cache_result(key) if self.cached(key) else self._get_content().get(key, default)
|
||||
|
||||
@export(u'真人发音', 0)
|
||||
@export(u'真人发音')
|
||||
def fld_sound(self):
|
||||
# base64.b64encode('bonjour') == 'Ym9uam91cg=='
|
||||
# https://api.frdic.com/api/v2/speech/speakweb?langid=fr&txt=QYNYm9uam91cg%3d%3d
|
||||
@ -78,30 +78,30 @@ class Esdict(WebService):
|
||||
except Exception as e:
|
||||
return ''
|
||||
|
||||
@export(u'音标', 1)
|
||||
@export(u'音标')
|
||||
def fld_phonetic(self):
|
||||
return self._get_field('phonitic')
|
||||
|
||||
@export(u'西汉-汉西词典', 2)
|
||||
@export(u'西汉-汉西词典')
|
||||
@with_styles(css=css)
|
||||
def fld_fccf(self):
|
||||
return self._get_field('fccf')
|
||||
|
||||
@export(u'西语例句库', 3)
|
||||
@export(u'西语例句库')
|
||||
@with_styles(css=css)
|
||||
def fld_example(self):
|
||||
return self._get_field('example')
|
||||
|
||||
@export(u'近义、反义、派生词典', 4)
|
||||
@export(u'近义、反义、派生词典')
|
||||
def fld_syn(self):
|
||||
return self._get_field('syn')
|
||||
|
||||
@export(u'西西词典', 5)
|
||||
@export(u'西西词典')
|
||||
@with_styles(css=css)
|
||||
def fld_ff(self):
|
||||
return self._get_field('ff')
|
||||
|
||||
@export(u'西英词典', 6)
|
||||
@export(u'西英词典')
|
||||
@with_styles(css=css)
|
||||
def fld_fe(self):
|
||||
return self._get_field('fe')
|
||||
|
||||
@ -63,7 +63,7 @@ class Frdic(WebService):
|
||||
except Exception as e:
|
||||
return {}
|
||||
|
||||
@export(u'真人发音', 0)
|
||||
@export(u'真人发音')
|
||||
def fld_sound(self):
|
||||
# base64.b64encode('bonjour') == 'Ym9uam91cg=='
|
||||
# https://api.frdic.com/api/v2/speech/speakweb?langid=fr&txt=QYNYm9uam91cg%3d%3d
|
||||
@ -79,30 +79,30 @@ class Frdic(WebService):
|
||||
def _get_field(self, key, default=u''):
|
||||
return self.cache_result(key) if self.cached(key) else self._get_content().get(key, default)
|
||||
|
||||
@export(u'音标', 1)
|
||||
@export(u'音标')
|
||||
def fld_phonetic(self):
|
||||
return self._get_field('phonitic')
|
||||
|
||||
@export(u'法汉-汉法词典', 2)
|
||||
@export(u'法汉-汉法词典')
|
||||
def fld_fccf(self):
|
||||
return self._get_field('fccf')
|
||||
|
||||
@export(u'法语例句库', 3)
|
||||
@export(u'法语例句库')
|
||||
@with_styles(css=css)
|
||||
def fld_example(self):
|
||||
return self._get_field('example')
|
||||
|
||||
@export(u'近义、反义、派生词典', 4)
|
||||
@export(u'近义、反义、派生词典')
|
||||
@with_styles(css=css)
|
||||
def fld_syn(self):
|
||||
return self._get_field('syn')
|
||||
|
||||
@export(u'法法词典', 5)
|
||||
@export(u'法法词典')
|
||||
@with_styles(css=css)
|
||||
def fld_ff(self):
|
||||
return self._get_field('ff')
|
||||
|
||||
@export(u'法英词典', 6)
|
||||
@export(u'法英词典')
|
||||
@with_styles(css=css)
|
||||
def fld_fe(self):
|
||||
return self._get_field('fe')
|
||||
|
||||
@ -40,19 +40,19 @@ class ICIBA(WebService):
|
||||
return self.cache_result(key) if self.cached(key) else self._get_content().get(key, default)
|
||||
|
||||
@ignore_exception
|
||||
@export(u'美式音标', 1)
|
||||
@export(u'美式音标')
|
||||
def fld_phonetic_us(self):
|
||||
seg = self._get_field('baesInfo')
|
||||
return '/' + seg['symbols'][0]['ph_am'] + '/'
|
||||
|
||||
@ignore_exception
|
||||
@export(u'英式音标', 2)
|
||||
@export(u'英式音标')
|
||||
def fld_phonetic_uk(self):
|
||||
seg = self._get_field('baesInfo')
|
||||
return '/' + seg['symbols'][0]['ph_en'] + '/'
|
||||
|
||||
@ignore_exception
|
||||
@export(u'美式发音', 3)
|
||||
@export(u'美式发音')
|
||||
def fld_mp3_us(self):
|
||||
seg = self._get_field('baesInfo')
|
||||
audio_url, t = seg['symbols'][0]['ph_am_mp3'], 'am'
|
||||
@ -65,7 +65,7 @@ class ICIBA(WebService):
|
||||
return audio_url
|
||||
|
||||
@ignore_exception
|
||||
@export(u'英式发音', 4)
|
||||
@export(u'英式发音')
|
||||
def fld_mp3_uk(self):
|
||||
seg = self._get_field('baesInfo')
|
||||
audio_url, t = seg['symbols'][0]['ph_en_mp3'], 'en'
|
||||
@ -78,14 +78,14 @@ class ICIBA(WebService):
|
||||
return audio_url
|
||||
|
||||
@ignore_exception
|
||||
@export(u'释义', 5)
|
||||
@export(u'释义')
|
||||
def fld_definition(self):
|
||||
seg = self._get_field('baesInfo')
|
||||
parts = seg['symbols'][0]['parts']
|
||||
return u'<br>'.join([part['part'] + ' ' + '; '.join(part['means']) for part in parts])
|
||||
|
||||
@ignore_exception
|
||||
@export(u'双语例句', 6)
|
||||
@export(u'双语例句')
|
||||
def fld_samples(self):
|
||||
sentences = ''
|
||||
segs = self._get_field('sentence')
|
||||
@ -98,7 +98,7 @@ class ICIBA(WebService):
|
||||
return u"""<ol>{}</ol>""".format(sentences)
|
||||
|
||||
@ignore_exception
|
||||
@export(u'权威例句', 7)
|
||||
@export(u'权威例句')
|
||||
def fld_auth_sentence(self):
|
||||
sentences = ''
|
||||
segs = self._get_field('auth_sentence')
|
||||
@ -109,7 +109,7 @@ class ICIBA(WebService):
|
||||
return u"""<ol>{}</ol>""".format(sentences)
|
||||
|
||||
@ignore_exception
|
||||
@export(u'句式用法', 8)
|
||||
@export(u'句式用法')
|
||||
def fld_usage(self):
|
||||
sentences = ''
|
||||
segs = self._get_field('jushi')
|
||||
@ -122,13 +122,13 @@ class ICIBA(WebService):
|
||||
return u"""<ol>{}</ol>""".format(sentences)
|
||||
|
||||
@ignore_exception
|
||||
@export(u'使用频率', 9)
|
||||
@export(u'使用频率')
|
||||
def fld_frequence(self):
|
||||
seg = self._get_field('baesInfo')
|
||||
return str(seg['frequence'])
|
||||
|
||||
@ignore_exception
|
||||
@export(u'英文例句', 10)
|
||||
@export(u'英文例句')
|
||||
def fld_st(self):
|
||||
sentences = ''
|
||||
segs = self._get_field('sentence')
|
||||
@ -139,7 +139,7 @@ class ICIBA(WebService):
|
||||
return sentences
|
||||
|
||||
@ignore_exception
|
||||
@export(u'例句翻译', 11)
|
||||
@export(u'例句翻译')
|
||||
def fld_sttr(self):
|
||||
sentences = ''
|
||||
segs = self._get_field('sentence')
|
||||
|
||||
@ -134,32 +134,32 @@ class Longman(WebService):
|
||||
return ''
|
||||
return self.cache_result(single_dict)
|
||||
|
||||
@export(u'音标', 2)
|
||||
def phonetic(self):
|
||||
@export(u'音标')
|
||||
def fld_phonetic(self):
|
||||
return self._get_singledict('phonetic')
|
||||
|
||||
@export(u'断字单词', 3)
|
||||
def hyphenation(self):
|
||||
@export(u'断字单词')
|
||||
def fld_hyphenation(self):
|
||||
return self._get_singledict('hyphenation')
|
||||
|
||||
@export(u'词性', 1)
|
||||
def pos(self):
|
||||
@export(u'词性')
|
||||
def fld_pos(self):
|
||||
return self._get_singledict('pos')
|
||||
|
||||
@export(u'英英解释', 0)
|
||||
@export(u'英英解释')
|
||||
@with_styles(cssfile='_longman.css')
|
||||
def ee(self):
|
||||
def fld_ee(self):
|
||||
return self._get_singledict('ee')
|
||||
|
||||
@export(u'图片', 4)
|
||||
def pic(self):
|
||||
@export(u'图片')
|
||||
def fld_pic(self):
|
||||
url = self._get_singledict('img')
|
||||
filename = u'longman_img_{}'.format(os.path.basename(url))
|
||||
if url and self.download(url, filename):
|
||||
return self.get_anki_label(filename, 'img')
|
||||
return ''
|
||||
|
||||
@export(u'变形', 5)
|
||||
@export(u'变形')
|
||||
@with_styles(cssfile='_longman.css')
|
||||
def inflections(self):
|
||||
def fld_inflections(self):
|
||||
return self._get_singledict('inflections')
|
||||
|
||||
@ -14,7 +14,7 @@ class MiniDict(WebService):
|
||||
super(MiniDict, self).__init__()
|
||||
self.encoder = Encoder()
|
||||
|
||||
def get_content(self, token):
|
||||
def _get_content(self, token):
|
||||
expressions, sentences, variations = [''] * 3
|
||||
|
||||
encoded_word = self.encoder.go(self.word, token)
|
||||
@ -31,7 +31,7 @@ class MiniDict(WebService):
|
||||
{'expressions': expressions, 'sentences': sentences, 'variations': variations})
|
||||
return expressions, sentences, variations
|
||||
|
||||
def get_token_phonetic(self):
|
||||
def _get_token_phonetic(self):
|
||||
result = self.get_response(
|
||||
"http://dict.cn/mini.php?q={}".format(self.word))
|
||||
|
||||
@ -45,39 +45,39 @@ class MiniDict(WebService):
|
||||
self.cache_this({'phonetic': phonetic})
|
||||
return page_token, phonetic
|
||||
|
||||
@export(u'音标', 0)
|
||||
@export(u'音标')
|
||||
# @with_css('''<style type="text/css">.p {font-family: Lucida Sans Unicode; color: #666699;}</style>''')
|
||||
def fld_phonetic(self):
|
||||
return self.cache_result('phonetic') if self.cached('phonetic') else self.get_token_phonetic()[1]
|
||||
return self.cache_result('phonetic') if self.cached('phonetic') else self._get_token_phonetic()[1]
|
||||
|
||||
@export(u'基本释义', 1)
|
||||
@export(u'基本释义')
|
||||
def fld_explains(self):
|
||||
if self.cached('expressions'):
|
||||
return self.cache_result('expressions')
|
||||
# showInfo(u'%s 基本释义cached:\n %s' % (self.word, res))
|
||||
else:
|
||||
page_token, phonetic = self.get_token_phonetic()
|
||||
return self.get_content(page_token)[0]
|
||||
page_token, phonetic = self._get_token_phonetic()
|
||||
return self._get_content(page_token)[0]
|
||||
# showInfo(u'%s 基本释义获取:\n %s' % (self.word, res))
|
||||
|
||||
@export(u'例句与用法', 2)
|
||||
@export(u'例句与用法')
|
||||
def fld_sentences(self):
|
||||
if self.cached('sentences'):
|
||||
return self.cache_result('sentences')
|
||||
# showInfo(u'%s 基本释义cached:\n %s' % (self.word, res))
|
||||
else:
|
||||
page_token, phonetic = self.get_token_phonetic()
|
||||
return self.get_content(page_token)[1]
|
||||
page_token, phonetic = self._get_token_phonetic()
|
||||
return self._get_content(page_token)[1]
|
||||
# showInfo(u'%s 基本释义获取:\n %s' % (self.word, res))
|
||||
|
||||
@export(u'词形变化', 3)
|
||||
@export(u'词形变化')
|
||||
def fld_variations(self):
|
||||
if self.cached('variations'):
|
||||
return self.cache_result('variations')
|
||||
# showInfo(u'%s 基本释义cached:\n %s' % (self.word, res))
|
||||
else:
|
||||
page_token, phonetic = self.get_token_phonetic()
|
||||
return self.get_content(page_token)[2]
|
||||
page_token, phonetic = self._get_token_phonetic()
|
||||
return self._get_content(page_token)[2]
|
||||
# showInfo(u'%s 基本释义获取:\n %s' % (self.word, res))
|
||||
|
||||
|
||||
|
||||
@ -26,6 +26,6 @@ class Oxford(WebService):
|
||||
|
||||
return response["results"]
|
||||
|
||||
@export("Lexical Category", 1)
|
||||
def _fld_category(self):
|
||||
@export("Lexical Category")
|
||||
def fld_category(self):
|
||||
return self._get_from_api()[0]["lexicalEntries"][0]["lexicalCategory"]
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# coding=utf-8
|
||||
#from warnings import filterwarnings
|
||||
from ..libs.bs4 import Tag
|
||||
from .base import WebService, export, register, with_styles, parseHtml
|
||||
from .base import WebService, export, register, with_styles, parse_html
|
||||
|
||||
#filterwarnings('ignore')
|
||||
|
||||
@ -59,17 +59,17 @@ class OxfordLearning(WebService):
|
||||
)
|
||||
return self.cache_result(single_dict)
|
||||
|
||||
@export('PHON', 0)
|
||||
def phonetic(self):
|
||||
@export('PHON')
|
||||
def fld_phonetic(self):
|
||||
return self._get_single_dict('phonetic')
|
||||
|
||||
@export([u'词性', u'POS'], 1)
|
||||
def pos(self):
|
||||
@export([u'词性', u'POS'])
|
||||
def fld_pos(self):
|
||||
return self._get_single_dict('pos')
|
||||
|
||||
@export('DEF', 2)
|
||||
@export('DEF')
|
||||
@with_styles(cssfile='_oxford.css')
|
||||
def ee(self):
|
||||
def fld_ee(self):
|
||||
# return '<div style="margin-left: 20px">' + self._get_single_dict(
|
||||
# 'ee') + "</div>" if "<li>" not in self._get_single_dict('ee') else self._get_single_dict('ee')
|
||||
return self._get_single_dict('ee')
|
||||
@ -88,16 +88,16 @@ class OxfordLearning(WebService):
|
||||
return self.get_anki_label(filename, 'audio')
|
||||
return ''
|
||||
|
||||
@export('BRE_PRON', 3)
|
||||
def sound_bre(self):
|
||||
@export('BRE_PRON')
|
||||
def fld_sound_bre(self):
|
||||
return self.get_sound_bre()
|
||||
|
||||
@export('AME_PRON', 4)
|
||||
def sound_ame(self):
|
||||
@export('AME_PRON')
|
||||
def fld_sound_ame(self):
|
||||
return self.get_sound_ame()
|
||||
|
||||
@export([u'英式发音优先', u'British Pronunciation First'], 5)
|
||||
def sound_pri(self):
|
||||
@export([u'英式发音优先', u'British Pronunciation First'])
|
||||
def fld_sound_pri(self):
|
||||
bre = self.get_sound_bre()
|
||||
return bre if bre else self.get_sound_ame()
|
||||
|
||||
@ -108,7 +108,7 @@ class OxfordLearningDictWord:
|
||||
if not markups:
|
||||
return
|
||||
self.markups = markups
|
||||
self.bs = parseHtml(self.markups)
|
||||
self.bs = parse_html(self.markups)
|
||||
self._defs = []
|
||||
self._defs_html = []
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class TxtTest(LocalService):
|
||||
except:
|
||||
self.handle = None
|
||||
|
||||
@export(u'all', 1)
|
||||
@export(u'all')
|
||||
def fld_phonetic(self):
|
||||
if not self.handle:
|
||||
return
|
||||
|
||||
@ -69,11 +69,11 @@ class Youdao(WebService):
|
||||
def _get_field(self, key, default=u''):
|
||||
return self.cache_result(key) if self.cached(key) else self._get_from_api().get(key, default)
|
||||
|
||||
@export(u'音标', 0)
|
||||
@export(u'音标')
|
||||
def fld_phonetic(self):
|
||||
return self._get_field('phonetic')
|
||||
|
||||
@export(u'基本释义', 1)
|
||||
@export(u'基本释义')
|
||||
def fld_explains(self):
|
||||
return self._get_field('explains')
|
||||
|
||||
@ -98,7 +98,7 @@ class Youdao(WebService):
|
||||
except:
|
||||
return ''
|
||||
|
||||
@export(u'英式发音', 2)
|
||||
@export(u'英式发音')
|
||||
def fld_british_audio(self):
|
||||
audio_url = u'http://dict.youdao.com/dictvoice?audio={}&type=1'.format(self.word)
|
||||
if youdao_download_mp3:
|
||||
@ -107,7 +107,7 @@ class Youdao(WebService):
|
||||
return self.get_anki_label(filename, 'audio')
|
||||
return audio_url
|
||||
|
||||
@export(u'美式发音', 3)
|
||||
@export(u'美式发音')
|
||||
def fld_american_audio(self):
|
||||
audio_url = u'http://dict.youdao.com/dictvoice?audio={}&type=2'.format(self.word)
|
||||
if youdao_download_mp3:
|
||||
@ -116,54 +116,54 @@ class Youdao(WebService):
|
||||
return self.get_anki_label(filename, 'audio')
|
||||
return audio_url
|
||||
|
||||
@export(u'柯林斯英汉', 4)
|
||||
@export(u'柯林斯英汉')
|
||||
def fld_collins(self):
|
||||
return self._get_singledict('collins')
|
||||
|
||||
@export(u'21世纪', 5)
|
||||
@export(u'21世纪')
|
||||
def fld_ec21(self):
|
||||
return self._get_singledict('ec21')
|
||||
|
||||
@export(u'英英释义', 6)
|
||||
@export(u'英英释义')
|
||||
def fld_ee(self):
|
||||
return self._get_singledict('ee')
|
||||
|
||||
@export(u'网络释义', 7)
|
||||
@export(u'网络释义')
|
||||
def fld_web_trans(self):
|
||||
return self._get_singledict('web_trans')
|
||||
|
||||
@export(u'同根词', 8)
|
||||
@export(u'同根词')
|
||||
def fld_rel_word(self):
|
||||
return self._get_singledict('rel_word')
|
||||
|
||||
@export(u'同近义词', 9)
|
||||
@export(u'同近义词')
|
||||
def fld_syno(self):
|
||||
return self._get_singledict('syno')
|
||||
|
||||
@export(u'双语例句', 10)
|
||||
@export(u'双语例句')
|
||||
def fld_blng_sents_part(self):
|
||||
return self._get_singledict('blng_sents_part')
|
||||
|
||||
@export(u'原生例句', 11)
|
||||
@export(u'原生例句')
|
||||
def fld_media_sents_part(self):
|
||||
return self._get_singledict('media_sents_part')
|
||||
|
||||
@export(u'权威例句', 12)
|
||||
@export(u'权威例句')
|
||||
def fld_auth_sents_part(self):
|
||||
return self._get_singledict('auth_sents_part')
|
||||
|
||||
@export(u'新英汉大辞典(中)', 13)
|
||||
@export(u'新英汉大辞典(中)')
|
||||
def fld_ce_new(self):
|
||||
return self._get_singledict('ce_new')
|
||||
|
||||
@export(u'百科', 14)
|
||||
@export(u'百科')
|
||||
def fld_baike(self):
|
||||
return self._get_singledict('baike')
|
||||
|
||||
@export(u'汉语词典(中)', 15)
|
||||
@export(u'汉语词典(中)')
|
||||
def fld_hh(self):
|
||||
return self._get_singledict('hh')
|
||||
|
||||
@export(u'专业释义(中)', 16)
|
||||
@export(u'专业释义(中)')
|
||||
def fld_special(self):
|
||||
return self._get_singledict('special')
|
||||
|
||||
@ -36,7 +36,7 @@ class Youdaofr(WebService):
|
||||
pass
|
||||
return self.cache_this(result)
|
||||
|
||||
@export(u'基本释义', 1)
|
||||
@export(u'基本释义')
|
||||
def fld_explains(self):
|
||||
return self.cache_result('explains') if self.cached('explains') else \
|
||||
self._get_from_api().get('explains', '')
|
||||
@ -62,18 +62,18 @@ class Youdaofr(WebService):
|
||||
except:
|
||||
return ''
|
||||
|
||||
@export(u'网络释义', 5)
|
||||
@export(u'网络释义')
|
||||
def fld_web_trans(self):
|
||||
return self._get_singledict('web_trans')
|
||||
|
||||
@export(u'双语例句', 8)
|
||||
@export(u'双语例句')
|
||||
def fld_blng_sents_part(self):
|
||||
return self._get_singledict('blng_sents_part')
|
||||
|
||||
@export(u'百科', 11)
|
||||
@export(u'百科')
|
||||
def fld_baike(self):
|
||||
return self._get_singledict('baike')
|
||||
|
||||
@export(u'汉语词典(中)', 13)
|
||||
@export(u'汉语词典(中)')
|
||||
def fld_hh(self):
|
||||
return self._get_singledict('hh')
|
||||
|
||||
@ -36,7 +36,7 @@ class Youdaoko(WebService):
|
||||
pass
|
||||
return self.cache_this(result)
|
||||
|
||||
@export(u'基本释义', 1)
|
||||
@export(u'基本释义')
|
||||
def fld_explains(self):
|
||||
return self.cache_result('explains') if self.cached('explains') else \
|
||||
self._get_from_api().get('explains', '')
|
||||
@ -62,18 +62,18 @@ class Youdaoko(WebService):
|
||||
except:
|
||||
return ''
|
||||
|
||||
@export(u'网络释义', 5)
|
||||
@export(u'网络释义')
|
||||
def fld_web_trans(self):
|
||||
return self._get_singledict('web_trans')
|
||||
|
||||
@export(u'双语例句', 8)
|
||||
@export(u'双语例句')
|
||||
def fld_blng_sents_part(self):
|
||||
return self._get_singledict('blng_sents_part')
|
||||
|
||||
@export(u'百科', 11)
|
||||
@export(u'百科')
|
||||
def fld_baike(self):
|
||||
return self._get_singledict('baike')
|
||||
|
||||
@export(u'汉语词典(中)', 13)
|
||||
@export(u'汉语词典(中)')
|
||||
def fld_hh(self):
|
||||
return self._get_singledict('hh')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user