add word 'async' & code formatting (#318)

* add word 'async' & code formatting

* Update the wrong pronunciation of 'async'

Co-authored-by: Yishuai Li <liyishuai@users.noreply.github.com>

Co-authored-by: Yishuai Li <liyishuai@users.noreply.github.com>
pull/323/head
Percy 4 years ago committed by GitHub
parent 6925c13aa7
commit 760220ea06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@
| array | [🔊](https://dict.youdao.com/dictvoice?audio=array&type=1) /ə'rei/ | [🔊](https://dict.youdao.com/dictvoice?audio=array&type=2) /əˈreɪ/ | ❌ /æ'rei/ | | array | [🔊](https://dict.youdao.com/dictvoice?audio=array&type=1) /ə'rei/ | [🔊](https://dict.youdao.com/dictvoice?audio=array&type=2) /əˈreɪ/ | ❌ /æ'rei/ |
| ASCII | [🔊](https://dict.youdao.com/dictvoice?audio=ascii&type=1) /'æski/ | [🔊](https://dict.youdao.com/dictvoice?audio=ascii&type=2) /ˈæski/ | ❌ /ɑːsk/ | | ASCII | [🔊](https://dict.youdao.com/dictvoice?audio=ascii&type=1) /'æski/ | [🔊](https://dict.youdao.com/dictvoice?audio=ascii&type=2) /ˈæski/ | ❌ /ɑːsk/ |
| aspect | [🔊](https://dict.youdao.com/dictvoice?audio=aspect&type=1) /'æspekt/ | [🔊](https://dict.youdao.com/dictvoice?audio=aspect&type=2) /ˈæspekt/ | ❌ /ə'spekt/ | | aspect | [🔊](https://dict.youdao.com/dictvoice?audio=aspect&type=1) /'æspekt/ | [🔊](https://dict.youdao.com/dictvoice?audio=aspect&type=2) /ˈæspekt/ | ❌ /ə'spekt/ |
| async | [🔊](https://dict.youdao.com/dictvoice?audio=async&type=1) /əˈsɪŋk/ | [🔊](https://dict.youdao.com/dictvoice?audio=async&type=2) /æˈsɪŋk/ | ❌ /'æsɪŋk/ |
| avatar | [🔊](https://dict.youdao.com/dictvoice?audio=avatar&type=1) /'ævətɑː/ | [🔊](https://dict.youdao.com/dictvoice?audio=avatar&type=2) /ˈævətɑːr/ | ❌ /ə'vʌtɑ/ | | avatar | [🔊](https://dict.youdao.com/dictvoice?audio=avatar&type=1) /'ævətɑː/ | [🔊](https://dict.youdao.com/dictvoice?audio=avatar&type=2) /ˈævətɑːr/ | ❌ /ə'vʌtɑ/ |
| Azure | [🔊](https://dict.youdao.com/dictvoice?audio=azure&type=1) /'æʒə/ | [🔊](https://dict.youdao.com/dictvoice?audio=azure&type=2) /ˈæʒər/ | ❌ /ˈæzʊʒə/ | | Azure | [🔊](https://dict.youdao.com/dictvoice?audio=azure&type=1) /'æʒə/ | [🔊](https://dict.youdao.com/dictvoice?audio=azure&type=2) /ˈæʒər/ | ❌ /ˈæzʊʒə/ |
| bind | [🔊](https://dict.youdao.com/dictvoice?audio=bind&type=1) /baɪnd/ | [🔊](https://dict.youdao.com/dictvoice?audio=bind&type=2) /baɪnd/ | ❌ /bɪnd/ | | bind | [🔊](https://dict.youdao.com/dictvoice?audio=bind&type=1) /baɪnd/ | [🔊](https://dict.youdao.com/dictvoice?audio=bind&type=2) /baɪnd/ | ❌ /bɪnd/ |

@ -4,11 +4,12 @@
Create the description for a word to be added to the word list Create the description for a word to be added to the word list
Usage: addword.py <word> Usage: addword.py <word>
""" """
import sys
import re import re
import sys
import urllib.request import urllib.request
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
def main(): def main():
"""Generate the information with pronunciations for a word to be added to the word list""" """Generate the information with pronunciations for a word to be added to the word list"""
if len(sys.argv) != 2: if len(sys.argv) != 2:
@ -16,34 +17,36 @@ def main():
sys.exit(1) sys.exit(1)
word = sys.argv[1] word = sys.argv[1]
pronunciations = get_pronunciations(word) pronunciations = get_pronunciations(word)
britsh_en = '[🔊](' + pronunciations[0][0] +')' + ' ' + '/' + pronunciations[0][1] + '/' britsh_en = '[🔊](' + pronunciations[0][0] + ')' + ' ' + '/' + pronunciations[0][1] + '/'
american_en = '[🔊](' + pronunciations[1][0] +')' + ' ' + '/' + pronunciations[1][1] + '/' american_en = '[🔊](' + pronunciations[1][0] + ')' + ' ' + '/' + pronunciations[1][1] + '/'
line = '| ' + word + ' | ' + britsh_en + ' | ' + american_en + ' | ' + ' ' + '|' line = '| ' + word + ' | ' + britsh_en + ' | ' + american_en + ' | ' + ' ' + '|'
print(line) print(line)
def get_pronunciations(word): def get_pronunciations(word):
"""Return the word's pronouciation URLs and phonetic transcriptions """Return the word's pronouciation URLs and phonetic transcriptions
from youdao.com if available""" from youdao.com if available"""
word = word.strip() word = word.strip()
word_url = "https://dict.youdao.com/w/en/"+word word_url = 'https://dict.youdao.com/w/en/' + word
pron_url = "https://dict.youdao.com/dictvoice?audio="+word+"&" pron_url = 'https://dict.youdao.com/dictvoice?audio='+ word + '&'
britsh_en = [" ", " "] britsh_en = [" ", " "]
american_en = [" "," "] american_en = [" ", " "]
try: try:
response = urllib.request.urlopen(word_url).read() response = urllib.request.urlopen(word_url).read()
soup = BeautifulSoup(response, "html.parser") soup = BeautifulSoup(response, 'html.parser')
spans = soup.find_all('span', {'class' : 'pronounce'}) spans = soup.find_all('span', {'class': 'pronounce'})
lines = [span.get_text() for span in spans] lines = [span.get_text() for span in spans]
match = re.findall(r'\[.+\]', lines[0]) match = re.findall(r'\[.+\]', lines[0])
britsh_en[0] = pron_url + "type=1" britsh_en[0] = pron_url + 'type=1'
britsh_en[1] = match[0].replace('[', '').replace(']', '') britsh_en[1] = match[0].replace('[', '').replace(']', '')
match = re.findall(r'\[.+\]', lines[1]) match = re.findall(r'\[.+\]', lines[1])
american_en[0] = pron_url + "type=2" american_en[0] = pron_url + 'type=2'
american_en[1] = match[0].replace('[', '').replace(']', '') american_en[1] = match[0].replace('[', '').replace(']', '')
except: except:
return britsh_en, american_en return britsh_en, american_en
return britsh_en, american_en return britsh_en, american_en
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save