From c2da61b6b868c073b49644f39708068dd4d84288 Mon Sep 17 00:00:00 2001 From: AugusMeow Date: Tue, 9 Jan 2024 23:15:56 +0800 Subject: [PATCH] fix: py --- 2024/01/08.md | 4 ++++ 2024/README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ run.py | 27 ++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 2024/01/08.md create mode 100644 2024/README.md diff --git a/2024/01/08.md b/2024/01/08.md new file mode 100644 index 0000000..dcb59d2 --- /dev/null +++ b/2024/01/08.md @@ -0,0 +1,4 @@ +# 2024/01/08 + +公司真的是一个很好的公司,但是团队的价值观好极端。公司的各个福利都非常不错,各个团队之间的差距真的大。 + diff --git a/2024/README.md b/2024/README.md new file mode 100644 index 0000000..285a107 --- /dev/null +++ b/2024/README.md @@ -0,0 +1,45 @@ +# 2024 + +## Jan + +|Sun|Mon|Tue|Wed|Thu|Fri|Sat| +|:---:|:---:|:---:|:---:|:---:|:---:|:---:| +| |01|02|03|04|05|06| +|07|[08][2024/01/08]|[09][2024/01/09]|10|11|12|13| +|14|15|16|17|18|19|20| +|21|22|23|24|25|26|27| +|28|29|30|31| | | | + + + +[2024/01/01]: https://draugus.github.io/diary/2024/01/01 +[2024/01/02]: https://draugus.github.io/diary/2024/01/02 +[2024/01/03]: https://draugus.github.io/diary/2024/01/03 +[2024/01/04]: https://draugus.github.io/diary/2024/01/04 +[2024/01/05]: https://draugus.github.io/diary/2024/01/05 +[2024/01/06]: https://draugus.github.io/diary/2024/01/06 +[2024/01/07]: https://draugus.github.io/diary/2024/01/07 +[2024/01/08]: https://draugus.github.io/diary/2024/01/08 +[2024/01/09]: https://draugus.github.io/diary/2024/01/09 +[2024/01/10]: https://draugus.github.io/diary/2024/01/10 +[2024/01/11]: https://draugus.github.io/diary/2024/01/11 +[2024/01/12]: https://draugus.github.io/diary/2024/01/12 +[2024/01/13]: https://draugus.github.io/diary/2024/01/13 +[2024/01/14]: https://draugus.github.io/diary/2024/01/14 +[2024/01/15]: https://draugus.github.io/diary/2024/01/15 +[2024/01/16]: https://draugus.github.io/diary/2024/01/16 +[2024/01/17]: https://draugus.github.io/diary/2024/01/17 +[2024/01/18]: https://draugus.github.io/diary/2024/01/18 +[2024/01/19]: https://draugus.github.io/diary/2024/01/19 +[2024/01/20]: https://draugus.github.io/diary/2024/01/20 +[2024/01/21]: https://draugus.github.io/diary/2024/01/21 +[2024/01/22]: https://draugus.github.io/diary/2024/01/22 +[2024/01/23]: https://draugus.github.io/diary/2024/01/23 +[2024/01/24]: https://draugus.github.io/diary/2024/01/24 +[2024/01/25]: https://draugus.github.io/diary/2024/01/25 +[2024/01/26]: https://draugus.github.io/diary/2024/01/26 +[2024/01/27]: https://draugus.github.io/diary/2024/01/27 +[2024/01/28]: https://draugus.github.io/diary/2024/01/28 +[2024/01/29]: https://draugus.github.io/diary/2024/01/29 +[2024/01/30]: https://draugus.github.io/diary/2024/01/30 +[2024/01/31]: https://draugus.github.io/diary/2024/01/31 diff --git a/run.py b/run.py index 050cdd5..3cebd6e 100644 --- a/run.py +++ b/run.py @@ -93,9 +93,19 @@ def everyday(y, m): if m: break # print(res) - fo = open(project_path + "/" + y + "/README.md", "ab+") + filename=project_path + "/" + y + "/README.md" + fo = open(filename, "ab+") fo.write(res.encode()) fo.close() + + # 前两行是否有年 + with open(filename, 'r') as file: + lines = file.readlines() + if lines and (y not in lines[0] and y not in lines[1]): + lines[0] = f"# {y}\n" + with open(filename, 'w') as file: + file.writelines(lines) + def add_prefix(a): @@ -225,6 +235,8 @@ def cp_file(): os.mkdir(project_path + '/' + new_in[0]) os.mkdir(project_path + '/' + new_in[0] + '/' + new_in[1]) print("mkdir year and month, y m is ", new_in[0], new_in[1]) + print("cp file: meanwhile add readme and all links about this month") + everyday(int(new_in[0]), int(new_in[1])) else: year_index = p1.index(new_in[0]) print("year index", year_index) @@ -293,6 +305,19 @@ def modify_line(y, m, d): find_str = '|' + d + '|' cur_month_line_idx = -1 next_month_line_idx = 999999 + + # 防止没有该文件 + # 检查文件是否存在 + if not os.path.isfile(filename): + # 文件不存在,创建文件 + with open(filename, 'w') as file: + # 文件已创建,可以在此处写入内容,如果不需要写入可以什么也不做 + pass + else: + # 文件存在,不做任何操作 + print("File already exists.") + + with open(filename, "r+", encoding='utf-8') as file_handle: all_line = file_handle.readlines() for idx, ll in enumerate(all_line):