From c669297e6143b77d56fde8d908e72030e8232f90 Mon Sep 17 00:00:00 2001 From: loopyme Date: Fri, 4 Sep 2020 10:12:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8D=E8=83=BD=E5=86=99=E5=9B=9E=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- src/cqu_cj/__init__.py | 2 +- src/cqu_cj/__main__.py | 22 +++++++++------------- src/cqu_cj/config/config.py | 2 +- src/cqu_cj/config/config.yaml | 5 ----- src/cqu_cj/utils.py | 20 +++++++++++--------- src/cqu_cj/version.py | 2 +- 7 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 src/cqu_cj/config/config.yaml diff --git a/setup.py b/setup.py index ccd3865..5c3f4b1 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -version = "0.1.3" +version = "0.1.4" # Read the contents of README file source_root = Path(".") diff --git a/src/cqu_cj/__init__.py b/src/cqu_cj/__init__.py index beb0690..65d2008 100644 --- a/src/cqu_cj/__init__.py +++ b/src/cqu_cj/__init__.py @@ -3,4 +3,4 @@ __all__ = ["main", "console_main"] -check_update('cqu-cj') +check_update("cqu-cj") diff --git a/src/cqu_cj/__main__.py b/src/cqu_cj/__main__.py index 9c0292c..4843821 100644 --- a/src/cqu_cj/__main__.py +++ b/src/cqu_cj/__main__.py @@ -18,8 +18,8 @@ def main(): } data = parse.urlencode( { - "username": config['user_info']['username'], - "password": config['user_info']['password'], + "username": config["user_info"]["username"], + "password": config["user_info"]["password"], "submit1.x": 36, "submit1.y": 16, } @@ -31,12 +31,15 @@ def main(): # Get grades page = session.get("http://oldjw.cqu.edu.cn:8088/score/sel_score/sum_score_sel.asp") - pd.read_html(page.content.decode('gbk'))[1].to_csv(config['output']['path'], index=None, header=None) + pd.read_html(page.content.decode("gbk"))[1].to_csv( + config["output"]["path"], index=None, header=None + ) log(f"已成功导出成绩到{config['output']['path']}") def console_main(): import argparse + check_output_path() def parse_args() -> argparse.Namespace: @@ -54,10 +57,7 @@ def parse_args() -> argparse.Namespace: help="显示版本号", ) parser.add_argument( - "-c", - "--config_path", - help="查询配置文件路径", - action="store_true", + "-c", "--config_path", help="查询配置文件路径", action="store_true", ) parser.add_argument( "-r", "--reset", help="重置配置项", action="store_true", @@ -77,11 +77,7 @@ def parse_args() -> argparse.Namespace: default=config["user_info"]["password"], ) parser.add_argument( - "-o", - "--output", - help="成绩输出路径", - type=str, - default=config['output']['path'], + "-o", "--output", help="成绩输出路径", type=str, default=config["output"]["path"], ) return parser.parse_args() @@ -99,6 +95,6 @@ def parse_args() -> argparse.Namespace: main() -if __name__ == '__main__': +if __name__ == "__main__": check_output_path() main() diff --git a/src/cqu_cj/config/config.py b/src/cqu_cj/config/config.py index 9fac4a0..9267a15 100644 --- a/src/cqu_cj/config/config.py +++ b/src/cqu_cj/config/config.py @@ -24,7 +24,7 @@ def __getitem__(self, item): return self.data.__getitem__(item) def dump(self): - self.path.write_text(yaml.dump(self.data, Dumper=yaml.SafeDumper)) + Config.path.write_text(yaml.dump(self.data, Dumper=yaml.SafeDumper)) @classmethod def reset(cls): diff --git a/src/cqu_cj/config/config.yaml b/src/cqu_cj/config/config.yaml deleted file mode 100644 index d922975..0000000 --- a/src/cqu_cj/config/config.yaml +++ /dev/null @@ -1,5 +0,0 @@ -output: - path: null -user_info: - password: 080413 - username: '20173998' diff --git a/src/cqu_cj/utils.py b/src/cqu_cj/utils.py index 632b82c..0a69c54 100644 --- a/src/cqu_cj/utils.py +++ b/src/cqu_cj/utils.py @@ -14,16 +14,16 @@ def check_output_path(): - if config['output']['path'] is None: + if config["output"]["path"] is None: flag = False for i in ["Desktop", "桌面", "desktop"]: if (Path.home() / i).is_dir(): flag = True break if flag: - config['output']['path'] = Path.home() / i / "成绩.csv" + config["output"]["path"] = str(Path.home() / i / "成绩.csv") else: - config['output']['path'] = Path("./成绩.csv").absolute() + config["output"]["path"] = str(Path("./成绩.csv").absolute()) def exit(): @@ -56,7 +56,7 @@ def check_user(): config["user_info"]["username"] is None or config["user_info"]["password"] is None ): - print("未找到有效的帐号和密码,请输入你的帐号和密码,它们将被保存在你的电脑上以备下次使用") + print("未找到有效的帐号和密码,请输入你的帐号和密码(一般是身份证后六位),它们将被保存在你的电脑上以备下次使用") try: config["user_info"]["username"] = input("帐号>>>") config["user_info"]["password"] = input("密码>>>") @@ -69,14 +69,16 @@ def check_user(): def check_update(project_name): try: - content = requests.get(f"https://pypi.org/project/{project_name}/").content.decode() - latest_version = re.findall(project_name + r" \d{1,2}\.\d{1,2}\.\d{1,2}", content)[ - 0 - ].lstrip(project_name + " ") + content = requests.get( + f"https://pypi.org/project/{project_name}/" + ).content.decode() + latest_version = re.findall( + project_name + r" \d{1,2}\.\d{1,2}\.\d{1,2}", content + )[0].lstrip(project_name + " ") if latest_version.split(".") > __version__.split("."): log( f"{project_name}的最新版本为{latest_version},当前安装的是{__version__},建议使用`pip install {project_name} -U`来升级", warning=True, ) except Exception: - pass \ No newline at end of file + pass diff --git a/src/cqu_cj/version.py b/src/cqu_cj/version.py index dc8cc6f..0e5b88b 100644 --- a/src/cqu_cj/version.py +++ b/src/cqu_cj/version.py @@ -1,2 +1,2 @@ """This file is auto-generated by setup.py, please do not alter.""" -__version__ = "0.1.3" +__version__ = "0.1.4"