Add Dreye online dictionary

This commit is contained in:
St.Huang 2018-09-12 11:26:42 +08:00
parent 1b6465039b
commit a1019af88c
4 changed files with 656 additions and 0 deletions

View File

@ -0,0 +1,74 @@
#-*- coding:utf-8 -*-
import re
import os
from ..base import *
dreye_download_mp3 = True
@register([u'译典通', u'Dr.eye'])
class Dreye(WebService):
def __init__(self):
super(Dreye, self).__init__()
def _get_from_api(self):
data = self.get_response(u"https://yun.dreye.com/dict_new/dict.php?w={}&hidden_codepage=01".format(self.quote_word))
soup = parse_html(data)
result = {
'phon': '',
'pron': '',
'pos': '',
'def': ''
}
#音标
element = soup.find('span', class_='phonetic')
if element:
result['phon'] = element.get_text()
# 发音
mp3_regexp = re.compile(r'var *RealSoundPath += +"(.*)";')
mp3_match = mp3_regexp.search(data.decode('utf-8'))
if mp3_match:
result['pron'] = u'{}'.format(mp3_match.group(1))
#动变
element = soup.find('div', id='digest')
if element:
result['pos'] = u'{}'.format(str(element))
#释义
element = soup.find('div', id='usual')
if element:
result['def'] = u'{}'.format(str(element))
return self.cache_this(result)
@with_styles(need_wrap_css=True, cssfile='_dreye.css')
def _css(self, val):
return val
@export('PHON')
def fld_phonetic_us(self):
return self._get_field('phon')
@export('PRON')
def fld_mp3(self):
audio_url = self._get_field('pron')
if dreye_download_mp3 and audio_url:
filename = get_hex_name('dreye', audio_url, 'mp3')
if os.path.exists(filename) or self.net_download(filename, audio_url):
return self.get_anki_label(filename, 'audio')
return ''
@export([u'摘要', u'Digest'])
def fld_pos(self):
val = self._get_field('pos')
if val == None or val == '':
return ''
return self._css(val)
@export('DEF')
def fld_definition(self):
val = self._get_field('def')
if val == None or val == '':
return ''
return self._css(val)

View File

@ -0,0 +1,254 @@
.content {
font-size: 14px;
color: #333333;
font-family: Microsoft YaHei, simhei;
}
.IntExpcontent {
line-height: 25px;
font-size: 14px;
color: #333333;
font-family: Microsoft YaHei, simhei;
}
.IntExpcontent p, ul, li, ol, h4, h3, h1 {
margin: 0;
padding: 0;
}
.IntExpcontent a {
line-height: 25px;
}
.IntExpcontent ol {
*padding-left: 2em;
padding-left: 30px;
}
.IntExpcontent .col {
color: #43b4c6;
}
.IntExpcontent img {
*margin: 3px 0;
*vertical-align: middle;
display: inline-block;
cursor: pointer;
margin-left: .5em;
}
.content p, ul, li, ol, h4, h3, h1, {
margin: 0;
padding: 0;
}
.content .col {
color: #43b4c6;
}
.content a.col {
margin-right: 1em;
text-decoration: none;
}
.content a[href].col:hover {
text-decoration: underline;
}
.content .attr {
color: #43b4c6;
/* font-weight:bold;
font-family:Geogia,"Times New Roman",serif;*/
margin-right: 5px;
}
.content span.label {
border: 1px solid #d6d6d6;
margin-right: 5px;
*padding: 1px;
}
.content ol.nonlist {
list-style-type: none;
list-style: none outside none;
/*margin-left:0;*/
padding-left: 0;
}
.content span.pho {
background-color: #43b4c6;
text-align: center;
padding: 0px 4px;
border-radius: 10px;
font-size: 12px;
color: #ffffff;
/* border:1px solid #43b4c6;*/
}
.phonetic {
font-family: Lucida Sans Unicode;
color: #333333;
}
.exp em {
font-style: normal;
}
.jp {
font-family: "ms gothic", arial, sans-serif;
}
h1.keyword {
line-height: 25px;
color: #43b4c6;
margin: 0;
word-wrap: break-word;
font-size: 16px;
}
.content h4 {
height: 25px;
line-height: 25px;
font-size: 15px;
background-color: #efefef;
}
.content ol {
list-style-position: inside;
}
.content ul {
list-style-type: none;
margin-left: 0;
}
.content li {
display: list-item;
}
.IntExpcontent li {
display: list-item;
}
small {
font-size: 80%;
}
sup {
*font-size: 12px;
}
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
.content p {
line-height: 25px;
word-wrap: break-word;
display: block;
*white-space: pre;
*word-wrap: break-word;
word-break: keep-all;
}
.content p.attr {
line-height: 25px;
word-wrap: break-word;
display: block;
white-space: normal;
}
/********************************/
.content img {
*margin: 7px 0;
*vertical-align: middle;
display: inline-block;
cursor: pointer;
margin-left: .5em;
}
.content p.dictsrc {
Text-align: right;
}
p.dictsrc {
line-height: 25px;
Text-align: right;
}
/*oxfordEE*/
.font-uc {
text-transform: uppercase;
}
.font-AN {
font-family: "Arial Narrow";
}
.font-uc-b {
text-transform: uppercase;
font-weight: bold;
}
.font-small {
font-size: 13px;
}
.font-bNTR {
font-family: "Times New Roman";
font-weight: bold;
}
.font-LSU {
font-family: "lucida sans unicode";
}
.font-MRS {
font-family: "MS Reference Specialty";
}
/*閔華華閔*/
.font-drtw {
font-family: "Dr.eye tw symbol";
}
.font-PL {
font-family: "PMingLiU";
}
.font-CS {
font-family: "Segoe UI";
}
/*佛學*/
.font-AUM {
font-family: "Arial Unicode MS";
}
.font-TMU {
font-family: "Tibetan Machine Uni";
}
/********************************/
hr.separate {
border-color: #c4e8f8;
border-top-style: solid;
border-width: 1px 0px 0px 0px;
margin-bottom: 15px;
}

View File

@ -0,0 +1,74 @@
#-*- coding:utf-8 -*-
import re
import os
from ..base import *
dreye_download_mp3 = True
@register([u'译典通', u'Dr.eye'])
class Dreye(WebService):
def __init__(self):
super(Dreye, self).__init__()
def _get_from_api(self):
data = self.get_response(u"https://yun.dreye.com/dict_new/dict.php?w={}&hidden_codepage=01".format(self.quote_word))
soup = parse_html(data)
result = {
'phon': '',
'pron': '',
'pos': '',
'def': ''
}
#音标
element = soup.find('span', class_='phonetic')
if element:
result['phon'] = element.get_text()
# 发音
mp3_regexp = re.compile(r'var *RealSoundPath += +"(.*)";')
mp3_match = mp3_regexp.search(data.decode('utf-8'))
if mp3_match:
result['pron'] = u'{}'.format(mp3_match.group(1))
#动变
element = soup.find('div', id='digest')
if element:
result['pos'] = u'{}'.format(str(element))
#释义
element = soup.find('div', id='usual')
if element:
result['def'] = u'{}'.format(str(element))
return self.cache_this(result)
@with_styles(need_wrap_css=True, cssfile='_dreye.css')
def _css(self, val):
return val
@export('PHON')
def fld_phonetic_us(self):
return self._get_field('phon')
@export('PRON')
def fld_mp3(self):
audio_url = self._get_field('pron')
if dreye_download_mp3 and audio_url:
filename = get_hex_name('dreye', audio_url, 'mp3')
if os.path.exists(filename) or self.net_download(filename, audio_url):
return self.get_anki_label(filename, 'audio')
return ''
@export([u'摘要', u'Digest'])
def fld_pos(self):
val = self._get_field('pos')
if val == None or val == '':
return ''
return self._css(val)
@export('DEF')
def fld_definition(self):
val = self._get_field('def')
if val == None or val == '':
return ''
return self._css(val)

View File

@ -0,0 +1,254 @@
.content {
font-size: 14px;
color: #333333;
font-family: Microsoft YaHei, simhei;
}
.IntExpcontent {
line-height: 25px;
font-size: 14px;
color: #333333;
font-family: Microsoft YaHei, simhei;
}
.IntExpcontent p, ul, li, ol, h4, h3, h1 {
margin: 0;
padding: 0;
}
.IntExpcontent a {
line-height: 25px;
}
.IntExpcontent ol {
*padding-left: 2em;
padding-left: 30px;
}
.IntExpcontent .col {
color: #43b4c6;
}
.IntExpcontent img {
*margin: 3px 0;
*vertical-align: middle;
display: inline-block;
cursor: pointer;
margin-left: .5em;
}
.content p, ul, li, ol, h4, h3, h1, {
margin: 0;
padding: 0;
}
.content .col {
color: #43b4c6;
}
.content a.col {
margin-right: 1em;
text-decoration: none;
}
.content a[href].col:hover {
text-decoration: underline;
}
.content .attr {
color: #43b4c6;
/* font-weight:bold;
font-family:Geogia,"Times New Roman",serif;*/
margin-right: 5px;
}
.content span.label {
border: 1px solid #d6d6d6;
margin-right: 5px;
*padding: 1px;
}
.content ol.nonlist {
list-style-type: none;
list-style: none outside none;
/*margin-left:0;*/
padding-left: 0;
}
.content span.pho {
background-color: #43b4c6;
text-align: center;
padding: 0px 4px;
border-radius: 10px;
font-size: 12px;
color: #ffffff;
/* border:1px solid #43b4c6;*/
}
.phonetic {
font-family: Lucida Sans Unicode;
color: #333333;
}
.exp em {
font-style: normal;
}
.jp {
font-family: "ms gothic", arial, sans-serif;
}
h1.keyword {
line-height: 25px;
color: #43b4c6;
margin: 0;
word-wrap: break-word;
font-size: 16px;
}
.content h4 {
height: 25px;
line-height: 25px;
font-size: 15px;
background-color: #efefef;
}
.content ol {
list-style-position: inside;
}
.content ul {
list-style-type: none;
margin-left: 0;
}
.content li {
display: list-item;
}
.IntExpcontent li {
display: list-item;
}
small {
font-size: 80%;
}
sup {
*font-size: 12px;
}
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
.content p {
line-height: 25px;
word-wrap: break-word;
display: block;
*white-space: pre;
*word-wrap: break-word;
word-break: keep-all;
}
.content p.attr {
line-height: 25px;
word-wrap: break-word;
display: block;
white-space: normal;
}
/********************************/
.content img {
*margin: 7px 0;
*vertical-align: middle;
display: inline-block;
cursor: pointer;
margin-left: .5em;
}
.content p.dictsrc {
Text-align: right;
}
p.dictsrc {
line-height: 25px;
Text-align: right;
}
/*oxfordEE*/
.font-uc {
text-transform: uppercase;
}
.font-AN {
font-family: "Arial Narrow";
}
.font-uc-b {
text-transform: uppercase;
font-weight: bold;
}
.font-small {
font-size: 13px;
}
.font-bNTR {
font-family: "Times New Roman";
font-weight: bold;
}
.font-LSU {
font-family: "lucida sans unicode";
}
.font-MRS {
font-family: "MS Reference Specialty";
}
/*閔華華閔*/
.font-drtw {
font-family: "Dr.eye tw symbol";
}
.font-PL {
font-family: "PMingLiU";
}
.font-CS {
font-family: "Segoe UI";
}
/*佛學*/
.font-AUM {
font-family: "Arial Unicode MS";
}
.font-TMU {
font-family: "Tibetan Machine Uni";
}
/********************************/
hr.separate {
border-color: #c4e8f8;
border-top-style: solid;
border-width: 1px 0px 0px 0px;
margin-bottom: 15px;
}