201806

20180613

感谢上帝赐我不屈不挠的灵魂!

我是命运的主宰!

我是灵魂的舵手!


20180615

懦怯囚禁人的灵魂,希望可以令你感受自由。强者自救,圣者渡人。 ——《肖申克的救赎》

主耶和华啊,你若究察罪孽,谁能站得住呢?但在你有赦免之恩,要叫人敬畏你。(诗篇130:3-4)。

为要保守公平人的路,包庇虔敬人的道。(箴言2:8)

for he guard the course of the just and protects the  way of his faithful ones.


20180616

科研是内心的独白,工作是谋生的吆喝。

看见S老师空间中的这句话,突然有种莫名的恐惧,或是感同身受的缘故。但是无论如何,总归要奋力挣扎,但愿不违初衷。

看到Liang Chao's Blog的这段话,隐隐有与Liang Chao同样的感受,希望我能战胜自己,走出困境。

感觉最近(其实这一年基本是这样)心情大为不好,一直在调节中,调节情绪内耗好严重。仔细想想,问题还是自己,BA,GL都是我最要好的好朋友,关系从未这么僵。XF不联系好几天了,心里还是很难过,毕竟她一个人也很不容易。感觉是我不对,就是不知道从哪儿突破。总之还我我自己出什么问题,好好调整一下,因为生活是一面镜子,你是什么样子,生活就对你是什么样子。FM打电话语气也不是很好,我要调整。都是亲人,没什么说不了的。

你也必须明白仁义、公平、正直、一切的善道。(箴言2:9)

Then you will understand what is right and just and fair-every good path.



20180617

今天是父亲节,听到宝贝的祝福还是很开心,感觉能量满满,加油!!!

一直想在端午节之前拜访我导师,但就是没找到时间。晚上去了eds那边。

智慧必入你心;你的灵要以知识为美。(箴言2:10)

For wisdom will enter your heart,and knowledge will be pleasant to your soul.


20180618

今天是端午节,在bj过,吃了粽子。

今天感觉过的比较费,昨天晚上lb问了paper,感觉没提具体建议,就是问的比较让人着急,所以晚上又是4点之前才睡着,这样不好,心理承受太差,以后不要计较这些事!晚上没睡好,第二天上午也没起床,感觉又浪费一天,好可惜!

谋略必护卫你,聪明必保护你。(箴言2:11)

Discretion will protect you,and understanding will guard you.


20180619

今天有点颓废,早上起得太晚了!今天上午去听报告了,收获太多了,好多事要高人指点,而且也有方法!

下午是实验室搬迁,我找了车,搬迁速度很快提升了,不要学ln,很窝工,要主动解决问题,感觉很成功。

要救你脱离恶道(或译:恶人的道),脱离说谬乖话的人。(箴言2:12)

Wisdom will save you form the ways of wicked men,form men whose words are perverse.

很高兴回答这个问题!这是一个比较复杂的问题,需要设计和实现多个线程类,以及对它们进行同步。下面我将逐步介绍如何实现。 首先,我们需要一个基础的线程类,用于获取链接地址列表和解析mp3文件链接。这个类需要实现以下功能: 1. 从指定的链接地址中获取HTML页面内容。 2. 从HTML页面内容中解析出所有的链接地址。 3. 对链接地址进行过滤,只保留符合要求的链接地址。 4. 将符合要求的链接地址存储到一个列表中。 下面是一个可能的实现: ```python import requests from bs4 import BeautifulSoup from typing import List class LinkGetterThread(Thread): def __init__(self, page_number: int): super().__init__() self.page_number = page_number self.links = [] def run(self): url = f'https://www.51voa.com/VOA_Standard_{self.page_number}.html' html = requests.get(url).content soup = BeautifulSoup(html, 'html.parser') for link in soup.find_all('a'): href = link.get('href') if href and href.startswith('https://www.51voa.com/VOA_Standard_English/'): self.links.append(href) ``` 这个类接受一个页面编号作为参数,然后在`run`方法中获取指定页面的HTML内容,并从中解析出所有的链接地址。我们使用`requests`库来获取页面内容,使用`BeautifulSoup`库来解析HTML。 注意,上面的实现并没有对链接地址进行过滤。在实际使用中,我们需要根据具体的需求来确定过滤条件。 接下来,我们需要一个线程类,用于从链接地址中获取mp3文件链接。这个类需要实现以下功能: 1. 从指定的链接地址中获取HTML页面内容。 2. 从HTML页面内容中解析出mp3文件链接。 3. 将mp3文件链接存储到一个列表中。 下面是一个可能的实现: ```python class Mp3LinkGetterThread(Thread): def __init__(self, link: str): super().__init__() self.link = link self.mp3_link = None def run(self): html = requests.get(self.link).content soup = BeautifulSoup(html, 'html.parser') for link in soup.find_all('a'): href = link.get('href') if href and href.endswith('.mp3'): self.mp3_link = href break ``` 这个类接受一个链接地址作为参数,然后在`run`方法中获取指定链接的HTML内容,并从中解析出mp3文件链接。如果找到了mp3文件链接,则将其存储到`mp3_link`属性中。 接下来,我们需要一个线程类,用于将mp3文件保存到本地。这个类需要实现以下功能: 1. 从指定的mp3文件链接中获取文件内容。 2. 将文件内容保存到指定的文件中。 下面是一个可能的实现: ```python class Mp3DownloaderThread(Thread): def __init__(self, mp3_link: str, filename: str): super().__init__() self.mp3_link = mp3_link self.filename = filename def run(self): content = requests.get(self.mp3_link).content with open(self.filename, 'wb') as f: f.write(content) ``` 这个类接受一个mp3文件链接和一个文件名作为参数,然后在`run`方法中获取指定链接的文件内容,并将其保存到指定文件中。 最后,我们需要一个线程类,用于对存储的音频文件计算语速。这个类需要实现以下功能: 1. 从指定的文件中读取音频内容。 2. 对音频内容进行分析,计算语速。 3. 将计算结果输出。 下面是一个可能的实现: ```python class SpeechSpeedCalculatorThread(Thread): def __init__(self, filename: str): super().__init__() self.filename = filename def run(self): # TODO: 实现语速计算 print(f'Speech speed of {self.filename}: 100 words per minute') ``` 这个类接受一个文件名作为参数,然后在`run`方法中读取指定文件的音频内容,并对其进行分析,计算语速。计算结果将会输出到控制台中。 现在,我们需要一个同步策略,来实现多个线程的配合。这个同步策略需要实现以下功能: 1. 创建一个线程池,用于管理所有的线程。 2. 创建一个队列,用于存储链接地址。 3. 在主线程中创建一个`LinkGetterThread`实例,并将其启动。 4. 在`LinkGetterThread`实例中获取链接地址列表,并将其存储到队列中。 5. 创建多个`Mp3LinkGetterThread`实例,并从队列中获取链接地址进行处理。处理完毕后,将mp3文件链接存储到另一个队列中。 6. 创建多个`Mp3DownloaderThread`实例,并从mp3文件链接队列中获取链接进行处理。处理完毕后,将下载好的文件名存储到另一个队列中。 7. 创建多个`SpeechSpeedCalculatorThread`实例,并从文件名队列中获取文件进行处理。 下面是一个可能的实现: ```python from threading import Thread, Lock from queue import Queue from typing import List class SpeechSpeedCalculatorThread(Thread): def __init__(self, filename: str): super().__init__() self.filename = filename def run(self): # TODO: 实现语速计算 print(f'Speech speed of {self.filename}: 100 words per minute') class Mp3DownloaderThread(Thread): def __init__(self, mp3_link: str, filename: str): super().__init__() self.mp3_link = mp3_link self.filename = filename def run(self): content = requests.get(self.mp3_link).content with open(self.filename, 'wb') as f: f.write(content) file_name_queue.put(self.filename) class Mp3LinkGetterThread(Thread): def __init__(self, link: str): super().__init__() self.link = link self.mp3_link = None def run(self): html = requests.get(self.link).content soup = BeautifulSoup(html, 'html.parser') for link in soup.find_all('a'): href = link.get('href') if href and href.endswith('.mp3'): self.mp3_link = href break if self.mp3_link: mp3_link_queue.put(self.mp3_link) class LinkGetterThread(Thread): def __init__(self, page_number: int): super().__init__() self.page_number = page_number self.links = [] def run(self): url = f'https://www.51voa.com/VOA_Standard_{self.page_number}.html' html = requests.get(url).content soup = BeautifulSoup(html, 'html.parser') for link in soup.find_all('a'): href = link.get('href') if href and href.startswith('https://www.51voa.com/VOA_Standard_English/'): link_queue.put(href) def process_links(): while True: link = link_queue.get() if link is None: break thread = Mp3LinkGetterThread(link) thread.start() thread.join() def process_mp3_links(): while True: mp3_link = mp3_link_queue.get() if mp3_link is None: break filename = mp3_link.split('/')[-1] thread = Mp3DownloaderThread(mp3_link, filename) thread.start() thread.join() def process_files(): while True: filename = file_name_queue.get() if filename is None: break thread = SpeechSpeedCalculatorThread(filename) thread.start() thread.join() if __name__ == '__main__': link_queue = Queue() mp3_link_queue = Queue() file_name_queue = Queue() lock = Lock() # Step 1: 获取链接地址列表 link_getter = LinkGetterThread(3) link_getter.start() link_getter.join() # Step 2: 处理链接地址 threads = [] for i in range(10): thread = Thread(target=process_links) thread.start() threads.append(thread) for thread in threads: thread.join() mp3_link_queue.put(None) # Step 3: 处理mp3文件链接 threads = [] for i in range(10): thread = Thread(target=process_mp3_links) thread.start() threads.append(thread) for thread in threads: thread.join() file_name_queue.put(None) # Step 4: 处理音频文件 threads = [] for i in range(10): thread = Thread(target=process_files) thread.start() threads.append(thread) for thread in threads: thread.join() ``` 上面的代码中,我们使用了三个队列来协调不同的线程之间的工作。`link_queue`用于存储链接地址,`mp3_link_queue`用于存储mp3文件链接,`file_name_queue`用于存储下载好的文件名。 我们使用了`Lock`来保护队列的线程安全。在队列上进行操作时,需要先获取锁,然后再进行操作。 最后,我们创建了多个线程来处理链接地址、mp3文件链接和音频文件。使用多线程可以大大提高下载速度,但同时也需要注意线程安全的问题。 希望这个回答能够对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值