Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Revert "修复有的词获取不到 defination 的问题 (#75)"
Browse files Browse the repository at this point in the history
This reverts commit c8f2f52.
  • Loading branch information
megachweng authored Nov 15, 2019
1 parent c8f2f52 commit 25525f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
26 changes: 4 additions & 22 deletions addon/queryApi/eudict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,11 @@ def __init__(self, html, term):

@property
def definition(self) -> list:
els = self._soap.select('div #ExpFCChild li') # 多词性
els = self._soap.select('div #ExpFCChild .exp') if not els else els # 单一词性
ret = []
div = self._soap.select('div #ExpFCChild')
if not div:
return ret

div = div[0]
els = div.select('li') # 多词性
if not els: # 单一词性
els = div.select('.exp')
if not els: # 还有一奇怪的情况,不在任何的标签里面
trans = div.find(id='trans')
trans.replace_with('') if trans else ''

script = div.find('script')
script.replace_with('') if script else ''

for atag in div.find_all('a'): # 赞踩这些字样
atag.replace_with('')
els = [div]

for el in els:
ret.append(el.get_text(strip=True))

return ret

@property
Expand Down Expand Up @@ -106,7 +88,7 @@ def sentence(self) -> list:
for el in els:
try:
line = el.select('p')
sentence = "".join([ str(c) for c in line[0].contents])
sentence = line[0].get_text(strip=True)
sentence_translation = line[1].get_text(strip=True)
ret.append((sentence, sentence_translation))
except KeyError as e:
Expand Down Expand Up @@ -170,7 +152,7 @@ def query(cls, word) -> dict:
queryResult = None
try:
rsp = cls.session.get(cls.url.format(word), timeout=cls.timeout)
logger.debug(f'code:{rsp.status_code}- word:{word} text:{rsp.text[:100]}')
logger.debug(f'code:{rsp.status_code}- word:{word} text:{rsp.text}')
queryResult = cls.parser(rsp.text, word).result
except Exception as e:
logger.exception(e)
Expand Down
15 changes: 1 addition & 14 deletions test/test_queryapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,7 @@ def test_eudict_with_none():
ret = check_result(res)
assert set(ret) - set(keys) == set()

def test_eudict_implication():
# 不包含图片,定义不在正常规则内,包含 trans
def test_eudict_implication_all():
res = api.query('implication')
ret = check_result(res)
assert set(ret) - set(['image']) == set()

def test_eudict_epitomize():
# 不包含图片,定义不在正常规则内
res = api.query('epitomize')
ret = check_result(res)
assert set(ret) - set(['image', 'phrase']) == set()

def test_eudict_periodical():
# 包含图片,定义不在正常规则内
res = api.query('periodical')
ret = check_result(res)
assert set(ret) - set(['image', 'phrase']) == set()

0 comments on commit 25525f4

Please sign in to comment.