Skip to content

Commit

Permalink
修复了配置文件不能写回的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
loopyme committed Sep 4, 2020
1 parent c42d6b3 commit c669297
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")
Expand Down
2 changes: 1 addition & 1 deletion src/cqu_cj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

__all__ = ["main", "console_main"]

check_update('cqu-cj')
check_update("cqu-cj")
22 changes: 9 additions & 13 deletions src/cqu_cj/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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:
Expand All @@ -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",
Expand All @@ -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()
Expand All @@ -99,6 +95,6 @@ def parse_args() -> argparse.Namespace:
main()


if __name__ == '__main__':
if __name__ == "__main__":
check_output_path()
main()
2 changes: 1 addition & 1 deletion src/cqu_cj/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 0 additions & 5 deletions src/cqu_cj/config/config.yaml

This file was deleted.

20 changes: 11 additions & 9 deletions src/cqu_cj/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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("密码>>>")
Expand All @@ -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
pass
2 changes: 1 addition & 1 deletion src/cqu_cj/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""This file is auto-generated by setup.py, please do not alter."""
__version__ = "0.1.3"
__version__ = "0.1.4"

0 comments on commit c669297

Please sign in to comment.