diff --git a/.github/workflows/update-progress.yml b/.github/workflows/update-progress.yml new file mode 100644 index 0000000..83060fb --- /dev/null +++ b/.github/workflows/update-progress.yml @@ -0,0 +1,33 @@ +name: Update Progress in Markdown + +on: + push: + paths: + - '**.md' + - update_progress.py + +permissions: + contents: write + +jobs: + update: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Run update script + run: python update_progress.py + + - name: Commit changes + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add README.md + git commit -m "Update progress" || echo "No changes to commit" + git push diff --git a/README.md b/README.md index 735e2c2..12842f2 100644 --- a/README.md +++ b/README.md @@ -662,5 +662,5 @@ 5. [500 Data Structures and Algorithms Practice Problems](https://kingrayhan.medium.com/500-data-structures-and-algorithms-practice-problems-and-their-solutions-b45a83d803f0) -**Progress: calculating...** +**Progress: 19.12% completed (104/544)** \ No newline at end of file diff --git a/update_progress.py b/update_progress.py new file mode 100644 index 0000000..afe6224 --- /dev/null +++ b/update_progress.py @@ -0,0 +1,26 @@ +import re + +MARKDOWN_FILE = "README.md" + +with open(MARKDOWN_FILE, "r") as f: + content = f.read() + +# Extract all checkboxes +tasks = re.findall(r"- \[( |x)\]", content, re.IGNORECASE) +total = len(tasks) +completed = tasks.count("x") + tasks.count("X") +percent = (completed / total * 100) if total > 0 else 0 +progress_line = f"**Progress: {percent:.2f}% completed ({completed}/{total})**" + +# Replace between markers +new_content = re.sub( + r".*?", + f"\n{progress_line}\n", + content, + flags=re.DOTALL +) + +with open(MARKDOWN_FILE, "w") as f: + f.write(new_content) + +print("Updated progress.")