Skip to content

Commit

Permalink
update to v2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dcp committed Dec 16, 2020
1 parent 224b57d commit 0041164
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ venv.bak/

.idea
*.un~

last_update_time*
accounts*
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UCAS Helper
![python version](https://img.shields.io/badge/python-3.5%2B-blue)
![demo version](https://img.shields.io/badge/version-2.0.5-brightgreen)
![demo version](https://img.shields.io/badge/version-2.1.1-brightgreen)
![license](https://img.shields.io/badge/license-GNU%20v3-yellowgreen)
```angular2
*********************************************************************************
Expand All @@ -10,7 +10,7 @@
** # # # ####### # # # # # # # # # **
** ### ### ## ## ### # # ### ##### # ### # # **
** copyright@GentleCP **
** version: 2.0.5 **
** version: 2.1.1 **
** github: https://github.com/GentleCP/UCASHelper **
** 1:course sources download **
** 2:wifi login **
Expand Down Expand Up @@ -80,6 +80,9 @@
![](img/1.7.0.png)

# 2. 更新日志
- [2.1.1] 本次做了两个主要改动:
1. 添加了自动更新的功能,在每次程序启动的时候检测github上的最新代码,若有更新,则同步更新,具体见[5.5 更新项目](#55-更新项目)
2. 修改了资源存储位置检测的顺序,放到了程序主界面启动之后,这样可以避免只想使用其他功能的朋友被强制要求设定资源下载路径
- [2.0.5] 修复登陆接口请求失败的问题,建议使用最新的更新方式,见[5.5 更新项目](#55-更新项目)
- [2.0.4] 修复评估教师失败的bug
- [2.0.3] 修复了部分课程因html解析不当导致的课程资源无法下载的情况,本次更新需要用到新的依赖包`lxml=4.5.2`
Expand Down Expand Up @@ -222,6 +225,10 @@ python ucashelper.py assess # 自动评教,评教内容在settings.py中设置
```

## 5.5 更新项目
- 现已支持程序启动时自动进行更新检查,在有更新的时候自动更新,不需要用户手动进行更新操作,如果你不希望每次都进行更新检查,可进入`settings.py`中设置`ALLOW_AUTO_UPDATE=False`
> 注意:由于自动更新依赖git,所以如果是通过`release`版本下载的代码无法使用自动更新功能,因此,本次也是最后一次发布`release`版本,后续更新都将采用此更新方式,如果你只想临时使用,不期待后续更新,可选择下载最新代码。

由于课程站点的变更,可能导致部分功能失效无法使用,待作者修复后,需要更新最新的版本代码到本地,现在提供自动化一条命令更新项目的方式。

> 需通过git方式部署,若直接下载源代码或`realease`压缩包,则需上github下载最新版本代码
Expand Down
5 changes: 3 additions & 2 deletions core/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def __init__(self, user_info, urls, source_dir,filter_list):
self._cur_course_info = None
self._collection_id_pattern = re.compile("value='(?P<collection_id>.*?)';") # 获取collection id 信息正则
self._dir_pattern = re.compile("value='/group/[0-9]*/(?P<dir>.*?)';") # 获取文件夹目录信息正则
self.__check_dir(self._source_dir)

def __check_dir(self, dir):

def _check_dir(self, dir):
if not os.path.exists(dir):
try:
os.mkdir(dir)
Expand Down Expand Up @@ -348,6 +348,7 @@ def _cmd(self):
break

def run(self):
self._check_dir(self._source_dir)
self.login()
self._set_course_info() # 添加所有课程信息到内存中
self._cmd() # 进入交互界面
Expand Down
78 changes: 51 additions & 27 deletions core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import logging
import time
import requests
import os

from core.assess import Assesser
from core.grade import GradeObserver
Expand All @@ -24,7 +26,7 @@
** # # # ####### # # # # # # # # # **
** ### ### ## ## ### # # ### ##### # ### # # **
** copyright@GentleCP **
** version: 2.0.5 **
** version: 2.1.1 **
** github: https://github.com/GentleCP/UCASHelper **
** 1:course sources download **
** 2:wifi login **
Expand All @@ -36,28 +38,54 @@
"""


class Init:
class Init(object):
"""
用于检查一切配置信息是否合理正确
"""

def __init__(self,
welcome_msg,
wifiLoginer=None,
downloader=None,
assesser= None,
gradeObserver = None,
):
def __init__(self, welcome_msg):
self._logger = logging.getLogger("Init")
self._welcome_msg = welcome_msg
self._wifi_loginer = wifiLoginer
self._downloader = downloader
self._assesser = assesser
self._grade_observer = gradeObserver

self._wifiLoginer = WifiLoginer(accounts_path=settings.ACCOUNTS_PATH)
self._downloader = Downloader(user_info=settings.USER_INFO,
urls=settings.URLS,
source_dir=settings.SOURCE_DIR,
filter_list=settings.FILTER_LIST)
self._assesser = Assesser(user_info=settings.USER_INFO,
urls=settings.URLS,
assess_msgs=settings.ASSESS_MSG)
self._gradeObserver = GradeObserver(user_info=settings.USER_INFO,
urls=settings.URLS)

def _show_welcome(self):
print(self._welcome_msg)


def _check_update(self, user="GentleCP", repo="UCAS-Helper"):
api = "https://api.github.com/repos/{user}/{repo}".format(user=user, repo=repo)
try:
latest_update_time = requests.get(api).json()["updated_at"]
except Exception:
self._logger.error("checking update faild.")
return False
try:
with open("last_update_time.txt", 'r') as f:
last_update_time = f.readline().strip()
except FileNotFoundError:
with open("last_update_time.txt", 'w') as f:
f.write(latest_update_time)
return True

if latest_update_time == last_update_time:
# already up to date
return False
else:
with open("last_update_time.txt", 'w') as f:
f.write(latest_update_time)
return True


def _cmd(self):
while True:
time.sleep(0.1)
Expand All @@ -78,39 +106,35 @@ def _cmd(self):

elif option == 2:
try:
self._wifi_loginer.login()
self._wifiLoginer.login()
except WifiError:
pass

elif option == 3:
try:
self._wifi_loginer.logout()
self._wifiLoginer.logout()
except WifiError:
pass

elif option == 4:
self._assesser.run()

elif option == 5:
self._grade_observer.run()
self._gradeObserver.run()

def run(self):
self._show_welcome()
if settings.ALLOW_AUTO_UPDATE and self._check_update():
# do update
self._logger.info("Available updates detected, start updating...")
os.system("git stash && git fetch --all && git merge && git stash pop")
self._logger.info("Update compelte.")
self._cmd()


def main():
wifiLoginer = WifiLoginer(accounts_path=settings.ACCOUNTS_PATH)
downloader = Downloader(user_info=settings.USER_INFO,
urls=settings.URLS,
source_dir=settings.SOURCE_DIR,
filter_list = settings.FILTER_LIST)
assesser = Assesser(user_info=settings.USER_INFO,
urls=settings.URLS,
assess_msgs=settings.ASSESS_MSG)
gradeObserver = GradeObserver(user_info=settings.USER_INFO,
urls=settings.URLS)
init = Init(WELCOME_MESSAGE, wifiLoginer, downloader,assesser, gradeObserver)

init = Init(WELCOME_MESSAGE)
init.run()


Expand Down
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'remember': 'undefined' # 此处不要动
}
SOURCE_DIR = ''
ALLOW_AUTO_UPDATE = True

# ------------------后面的不要动--------------#

Expand Down

0 comments on commit 0041164

Please sign in to comment.