From 711a072237606637d7b223092f66fbf17f96e6d3 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Fri, 25 Feb 2022 00:20:34 +0800 Subject: [PATCH] update --- .../download_word_mp3.py | 0 .../play_mp3_with_guan.py | 0 .../play_mp3_version1.py | 40 ------------------- .../play_mp3_version2.py | 26 ------------ 4 files changed, 66 deletions(-) rename {language_learning/2021.12.08_academic_words => academic_codes/2020.11.25_academic_words}/download_word_mp3.py (100%) rename {language_learning/2021.12.08_academic_words => academic_codes/2020.11.25_academic_words}/play_mp3_with_guan.py (100%) delete mode 100644 language_learning/2021.12.08_academic_words/play_mp3_version1.py delete mode 100644 language_learning/2021.12.08_academic_words/play_mp3_version2.py diff --git a/language_learning/2021.12.08_academic_words/download_word_mp3.py b/academic_codes/2020.11.25_academic_words/download_word_mp3.py similarity index 100% rename from language_learning/2021.12.08_academic_words/download_word_mp3.py rename to academic_codes/2020.11.25_academic_words/download_word_mp3.py diff --git a/language_learning/2021.12.08_academic_words/play_mp3_with_guan.py b/academic_codes/2020.11.25_academic_words/play_mp3_with_guan.py similarity index 100% rename from language_learning/2021.12.08_academic_words/play_mp3_with_guan.py rename to academic_codes/2020.11.25_academic_words/play_mp3_with_guan.py diff --git a/language_learning/2021.12.08_academic_words/play_mp3_version1.py b/language_learning/2021.12.08_academic_words/play_mp3_version1.py deleted file mode 100644 index f6c9ad1..0000000 --- a/language_learning/2021.12.08_academic_words/play_mp3_version1.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -This code is supported by the website: https://www.guanjihuan.com -The newest version of this code is on the web page: https://www.guanjihuan.com/archives/18038 -""" - -from bs4 import BeautifulSoup -import re -import urllib.request -import os -import pygame -import time -import ssl -import random -ssl._create_default_https_context = ssl._create_unverified_context -html = urllib.request.urlopen("https://www.guanjihuan.com/archives/4418").read().decode('utf-8') - -# directory = 'words_mp3_breProns/' # 英音 -directory = 'words_mp3_ameProns/' # 美音 -pygame.mixer.init() -soup = BeautifulSoup(html, features='lxml') -contents = re.findall('

.*?

', html, re.S) -# random.shuffle(contents) # 随机播放 -for content in contents: - soup2 = BeautifulSoup(content, features='lxml') - all_h2 = soup2.find_all('h2') - for h2 in all_h2: - if re.search('\d*. ', h2.get_text()): - word = re.findall('[a-zA-Z].*', h2.get_text(), re.S)[0] - exist = os.path.exists(directory+word+'.mp3') - if not exist: - continue - print(h2.get_text()) - # print('https://www.ldoceonline.com/dictionary/'+word) - track = pygame.mixer.music.load(directory+word+'.mp3') - pygame.mixer.music.play() - translation = re.findall('

.*?

', content, re.S)[0][3:-4] - time.sleep(2) - print(translation, '\n') - time.sleep(1) # 调节间隔时间 - pygame.mixer.music.stop() \ No newline at end of file diff --git a/language_learning/2021.12.08_academic_words/play_mp3_version2.py b/language_learning/2021.12.08_academic_words/play_mp3_version2.py deleted file mode 100644 index 23a9c38..0000000 --- a/language_learning/2021.12.08_academic_words/play_mp3_version2.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -This code is supported by the website: https://www.guanjihuan.com -The newest version of this code is on the web page: https://www.guanjihuan.com/archives/18038 -""" - -import pygame -import time -import os -import random - -# directory = 'words_mp3_breProns/' # 英音 -directory = 'words_mp3_ameProns/' # 美音 -pygame.mixer.init() -for root, dirs, files in os.walk(directory): - num_array = list(range(len(files))) - random.shuffle(num_array) # 随机播放 - j0 = 0 - for i0 in num_array: - j0 += 1 - print(j0) - print(files[i0][:-4]) - print('https://www.ldoceonline.com/dictionary/'+files[i0][:-4], '\n') - track = pygame.mixer.music.load(directory+files[i0]) - pygame.mixer.music.play() - time.sleep(3) # 调节间隔时间 - pygame.mixer.music.stop() \ No newline at end of file