Skip to content

Commit

Permalink
Update All Contributors Details in Raedme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
subhadipbhowmik committed May 23, 2024
1 parent 2c9395f commit 133e54f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .github/workflows/update_contributors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Update Contributors

on:
schedule:
- cron: '0 0 * * 1' # Runs every Monday at 00:00
push:
branches:
- main

jobs:
update-readme:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: pip install requests

- name: Run update script
run: python update_contributors.py

- name: Commit changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m 'Update contributors list'
git push
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Welcome to the 30 Days of CPP challenge! 30 days of CPP programming challenge is

![30-Days-CPP](./static/img/30-days-cpp.png)


## What is 30 Days of CPP?

30 Days of CPP is a programming challenge designed to help individuals enhance their proficiency in C++ by solving daily coding problems, implementing algorithms, and exploring various aspects of the language.
Expand Down Expand Up @@ -104,6 +103,14 @@ If you would like to contribute additional exercises, improvements, or correctio
Happy coding!
![Line](https://user-images.githubusercontent.com/85225156/171937799-8fc9e255-9889-4642-9c92-6df85fb86e82.gif)
## Contributors List
| Avatar | Name | GitHub Profile |
|--------|------|----------------|
## License
Expand Down
36 changes: 36 additions & 0 deletions update_contributors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import requests

username = 'subhadipbhowmik'
repo = '30-Days-Of-CPP'
url = f'https://api.github.com/repos/{username}/{repo}/contributors'

response = requests.get(url)
contributors = response.json()

contributors_list = []

for contributor in contributors:
avatar_url = contributor['avatar_url']
login = contributor['login']
profile_url = contributor['html_url']

contributors_list.append(f"| ![avatar]({avatar_url}&s=50) | [{login}]({profile_url}) |")

with open('README.md', 'r') as file:
readme_content = file.readlines()

# Find the index to insert contributors
start_index = readme_content.index('| Avatar | Name | GitHub Profile |\n') + 2

# Remove existing contributors data
while readme_content[start_index].startswith('| ![avatar]'):
readme_content.pop(start_index)

# Insert new contributors data
for contributor in contributors_list:
readme_content.insert(start_index, f"{contributor}\n")
start_index += 1

# Write the updated content back to README.md
with open('README.md', 'w') as file:
file.writelines(readme_content)

0 comments on commit 133e54f

Please sign in to comment.