Skip to content

Commit

Permalink
feature: 1. 同步完成后自动开启资源目录 2. 允许手动添加不被同步的课程
Browse files Browse the repository at this point in the history
  • Loading branch information
GentleCP committed Mar 27, 2020
1 parent f308bce commit 3e5e1d5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@

# 2. 版本号

1.4.3
1.5.0

## 2.1 更新内容
- [1.5.0]
- 课程资源同步后有新的资源时会提示是否开启资源所在目录,简便查看文件操作,如下
![](img/1.5.0-1.png)
- 允许添加不希望被同步的课程内容:在同步所有的时候有一门课的资源并没什么卵用,但为了一门而去一个个同步其他的又略显麻烦,
因此添加了一个`FILTER_LIST`,存放不想被同步的课程目录。打开`settings.py`,找到`FILTER_LIST`
将不像被同步的课程全名(如`没啥用课19-20春季`),添加到列表当中,如下:
![](img/1.5.0-2.png)

- 新版本在同步更新完成后会自动退出,不需要再手动退出程序

- [1.4.3]
> 修复了当同时存在多个文件夹和文件时不会下载与文件夹同目录的文件的问题,如下图所示:
![](img/fix_1.4.3-1.png)
Expand Down
3 changes: 2 additions & 1 deletion core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def main():
wifi_loginer = WifiLoginer(accounts_path=settings.ACCOUNTS_PATH)
downloader = Downloader(user_info=settings.USER_INFO,
urls=settings.URLS,
source_dir=settings.SOURCE_DIR)
source_dir=settings.SOURCE_DIR,
filter_list = settings.FILTER_LIST)
assesser = Assesser(settings.USER_INFO, settings.URLS,settings.ASSESS_MSG)
init = Init(WELCOME_MESSAGE, wifi_loginer, downloader,assesser)
init.run()
Expand Down
33 changes: 29 additions & 4 deletions core/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ def _login(self):


class Downloader(Loginer):
def __init__(self, user_info, urls, source_dir):
def __init__(self, user_info, urls, source_dir,filter_list):
super().__init__(user_info, urls)
self._logger = logging.getLogger("Downloader")
self._source_dir = source_dir
self._filter_list = filter_list
self._update_sources = []
self._l_course_info = []
self._d_source_info = {}
Expand Down Expand Up @@ -228,24 +229,48 @@ def _download_course(self, course_info):

def _download_all(self):
for course_info in self._l_course_info:
self._set_source_info(course_info)
self._download_course(course_info)
if course_info['name'] not in self._filter_list:
self._set_source_info(course_info)
self._download_course(course_info)
if self._update_sources:
self._logger.info("[同步完成] 本次更新资源列表如下:")
for source in self._update_sources:
print('\033[1;41m'+source+'\033[0m')
else:
self._logger.info("[同步完成] 本次无更新内容!")

def __open_dir(self):
'''
当同步完成的时候,打开对应的目录
:return:
'''
if sys.platform.startswith('win'):
result = os.system('start ' + self._source_dir)
elif sys.platform.startswith('linux'):
result = os.system('nautilus ' + self._source_dir)
else:
result = os.system('open ' + self._source_dir)
if result == 0:
print("已为您打开资源目录,请根据更新资源列表查询对应文件!")
else:
print("打开资源目录失败,请手动开启!")

def _download_course_by_season(self,season):
for course_info in self._l_course_info:
if season in course_info['name']:
if season in course_info['name'] and course_info['name'] not in self._filter_list:
self._set_source_info(course_info)
self._download_course(course_info)

if self._update_sources:
self._logger.info("[同步完成] 本次更新资源列表如下:")
for source in self._update_sources:
print('\033[1;41m' + source + '\033[0m')

is_open = input("是否打开资源所在目录(默认n)?(y/n)")
if is_open:
self.__open_dir()
exit(200)

else:
self._logger.info("[同步完成] 本次无更新内容!")

Expand Down
Binary file added img/1.5.0-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/1.5.0-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@
'item_43': '我觉得这个老师讲课十分有趣,课堂氛围十分活跃,是我喜欢的地方!', # 这位老师的教学,你最喜欢什么?
'item_44': '老师简直完美,我对老师的敬仰犹如滔滔江水,连绵不绝!!!!' # 您对老师有哪些意见和建议?
}


# Do not download list
FILTER_LIST = [
'没啥卵用课-1 19-20春季',
'有点卵用课-2 19-20春季', # 多个之间逗号隔开,务必输入课程全称!
]

0 comments on commit 3e5e1d5

Please sign in to comment.