diff --git a/main.py b/main.py index 6adcc48..0206f2f 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ from readme_level import ReadmeLevel -readme_instance: ReadmeLevel = ReadmeLevel() def draw_progress_bar() -> str: @@ -31,25 +30,29 @@ def draw_progress_bar() -> str: return progress_bar -user_level, to_next_lvl = itemgetter("current_level", - "percentage_level")(readme_instance.calc_current_level()) +if __name__ == "__main__": -readme_path: str = getenv("INPUT_README_PATH") -start_section: str = "" -end_section: str = "" -search_pattern: str = fr"{start_section}[\s\S]*?{end_section}" -replace_str: str = (f"{start_section}\n" - "```text\n" - f"level: { user_level } { draw_progress_bar() } {round(to_next_lvl, 2)}%\n" - "```\n" - f"{end_section}") + readme_instance: ReadmeLevel = ReadmeLevel() + user_level, to_next_lvl = itemgetter("current_level", + "percentage_level")(readme_instance.calc_current_level()) -# update readme -with open(readme_path, mode="r", encoding="utf-8") as readme_file: - readme_content = readme_file.read() + readme_path: str = getenv("INPUT_README_PATH") + start_section: str = "" + end_section: str = "" + search_pattern: str = fr"{start_section}[\s\S]*?{end_section}" + replace_str: str = (f"{start_section}\n" + "```text\n" + f"level: { user_level } { draw_progress_bar() } {round(to_next_lvl, 2)}%\n" + "```\n" + f"{end_section}") -changed_readme = sub(search_pattern, repl=replace_str, string=readme_content) -with open(readme_path, mode="w", encoding="utf-8") as readme_file: - readme_file.write(changed_readme) + # update readme + with open(readme_path, mode="r", encoding="utf-8") as readme_file: + readme_content = readme_file.read() + + changed_readme = sub(search_pattern, repl=replace_str, string=readme_content) + + with open(readme_path, mode="w", encoding="utf-8") as readme_file: + readme_file.write(changed_readme)