Skip to content

Commit

Permalink
fix: check if script was called directly
Browse files Browse the repository at this point in the history
  • Loading branch information
devfle committed Dec 16, 2022
1 parent 2f541c7 commit 6d54bd4
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from readme_level import ReadmeLevel


readme_instance: ReadmeLevel = ReadmeLevel()


def draw_progress_bar() -> str:
Expand All @@ -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 = "<!--README_LEVEL_UP:START-->"
end_section: str = "<!--README_LEVEL_UP:END-->"
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 = "<!--README_LEVEL_UP:START-->"
end_section: str = "<!--README_LEVEL_UP:END-->"
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)

0 comments on commit 6d54bd4

Please sign in to comment.