Skip to content

Commit

Permalink
Merge pull request #183 from DerickIT/main
Browse files Browse the repository at this point in the history
Add automated sync study status scripts
  • Loading branch information
DerickIT authored Jun 28, 2024
2 parents 11d495f + d1d6dfd commit ef996c1
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 35 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/sync_status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Update README

on:
schedule:
- cron: '0 0 * * *' # 每天午夜运行
push:
branches: [ main ] # 每次推送到main分支时也运行

jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub pytz
- name: Update README
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python sync_status_readme.py
- name: Commit changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Update commit status table" || exit 0
git push
77 changes: 42 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,49 @@ LXDAO Host 的英语残酷共学第 1 期将着重加强**听和说**的训练
## 3 英语残酷共学记录表

✅ = Done ⭕️ = Missed ❌ = Failed

| EICL1st· Name | 6.24 | 6.25 | 6.26 | 6.27 | 6.28 | 6.29 | 6.30 | 7.01 | 7.02 | 7.03 | 7.04 | 7.05 | 7.06 | 7.07 | 7.08 | 7.09 | 7.10 | 7.11 | 7.12 | 7.13 | 7.14 |
<!-- START_COMMIT_TABLE -->
| EICL1st· Name | 06.24 | 06.25 | 06.26 | 06.27 | 06.28 | 06.29 | 06.30 | 07.01 | 07.02 | 07.03 | 07.04 | 07.05 | 07.06 | 07.07 | 07.08 | 07.09 | 07.10 | 07.11 | 07.12 | 07.13 | 07.14 |
| ------------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| Bruce |||||| | | | | | | | | | | | | | | | |
| Oscar |||||| | | | | | | | | | | | | | | | |
| Muxin |||||| | | | | | | | | | | | | | | | |
| Coooder ||||| ⭕️ | | | | | | | | | | | | | | | | |
| Cooper || ⭕️ ||| | | | | | | | | | | | | | | | | |
| Connie ||||| | | | | | | | | | | | | | | | | |
| Louis || ⭕️ || ⭕️ || | | | | | | | | | | | | | | | |
| Derick |||||| | | | | | | | | | | | | | | | |
| Breeze |||| | | | | | | | | | | | | | | | | | |
| LoKi | ⭕️ ||| | | | | | | | | | | | | | | | | | |
| Wyatt |||⭕️ |⭕️ || | | | | | | | | | | | | | | | |
| Nicole |||| | | | | | | | | | | | | | | | | | |
| Odyssey ||| | | | | | | | | | | | | | | | | | | |
| Hansen |||||| | | | | | | | | | | | | | | | |
| Young ||| ⭕️ || | | | | | | | | | | | | | | | | |
| $PENY |||||| | | | | | | | | | | | | | | | |
| Yiming |||||| | | | | | | | | | | | | | | | |
| Piper || | | | | | | | | | | | | | | | | | | | |
| ZhaoHong |||||| | | | | | | | | | | | | | | | |
| Pignard ||||| | | | | | | | | | | | | | | | | |
| leo1226 |||||| | | | | | | | | | | | | | | | |
| loxia ||| ⭕️ | ⭕️ || | | | | | | | | | | | | | | | |
| WODECHE |||||| | | | | | | | | | | | | | | | |
| Junhua || ⭕️ |||| | | | | | | | | | | | | | | | |
| Ocean |||||| | | | | | | | | | | | | | | | |
| Ray |||||| | | | | | | | | | | | | | | | |
| cikey |||||| | | | | | | | | | | | | | | | |
| Nour |||| | | | | | | | | | | | | | | | | | |
| Jason |||||| | | | | | | | | | | | | | | | |
| Aiden |||| | | | | | | | | | | | | | | | | | |
| Tb ||||| ⭕️ | | | | | | | | | | | | | | | | |
| Marcus |||| | | | | | | | | | | | | | | | | | |
| Uint8 |||||| | | | | | | | | | | | | | | | |
| brucexu-eth |||||| ⭕️ | | | | | | | | | | | | | | | |
| Nourbit |||| ⭕️ | ⭕️ || | | | | | | | | | | | | | | |
| tttzzhh ||||| ⭕️ | ⭕️ | | | | | | | | | | | | | | | |
| ShelynL | ⭕️ | ⭕️ ||||| | | | | | | | | | | | | | | |
| Web3Pignard ||||| ⭕️ | ⭕️ | | | | | | | | | | | | | | | |
| LunaWang5209 | ⭕️ | ⭕️ ||||| | | | | | | | | | | | | | | |
| Tboj ||| ⭕️ ||| ⭕️ | | | | | | | | | | | | | | | |
| GeeekerK | ⭕️ | ⭕️ ||||| | | | | | | | | | | | | | | |
| OdysseyLee ||| ⭕️ | ⭕️ ||| | | | | | | | | | | | | | | |
| ymjrcc |||||| ⭕️ | | | | | | | | | | | | | | | |
| wodeche |||||| ⭕️ | | | | | | | | | | | | | | | |
| rich-loam ||||| ⭕️ | ⭕️ | | | | | | | | | | | | | | | |
| coderprepares ||| ⭕️ ||| ⭕️ | | | | | | | | | | | | | | | |
| muxin-web3 |||||| ⭕️ | | | | | | | | | | | | | | | |
| piperTang | ⭕️ | ⭕️ ||||| | | | | | | | | | | | | | | |
| minye420 | ⭕️ | ⭕️ ||||| | | | | | | | | | | | | | | |
| weifengHuang || ⭕️ | ⭕️ |||| | | | | | | | | | | | | | | |
| hweu |||| ⭕️ | ⭕️ || | | | | | | | | | | | | | | |
| DasNarrenschiff ||| ⭕️ | ⭕️ ||| | | | | | | | | | | | | | | |
| MRzzz-cyber |||| ⭕️ | ⭕️ || | | | | | | | | | | | | | | |
| UnsignedInt8 |||||| ⭕️ | | | | | | | | | | | | | | | |
| cikey247 |||||| ⭕️ | | | | | | | | | | | | | | | |
| qingfengzxr || ⭕️ ||| ⭕️ || | | | | | | | | | | | | | | |
| actions-user | ⭕️ | ⭕️ ||||| | | | | | | | | | | | | | | |
| Hu-Wentao ||| ⭕️ | ⭕️ ||| | | | | | | | | | | | | | | |
| Lookofsea |||||| ⭕️ | | | | | | | | | | | | | | | |
| youngtongyang ||| ⭕️ || ⭕️ || | | | | | | | | | | | | | | |
| LouiseCat || ⭕️ || ⭕️ ||| | | | | | | | | | | | | | | |
| DerickIT |||||| ⭕️ | | | | | | | | | | | | | | | |
| nocb |||||| ⭕️ | | | | | | | | | | | | | | | |
| rayjun || ⭕️ || ⭕️ ||| | | | | | | | | | | | | | | |
| penny777eth |||||| ⭕️ | | | | | | | | | | | | | | | |
| sfgshxgg | ⭕️ | ⭕️ ||||| | | | | | | | | | | | | | | |
| CNcoooder |||||| ⭕️ | | | | | | | | | | | | | | | |
| zhuyansen |||||| ⭕️ | | | | | | | | | | | | | | | |
| luffythink |||||| ⭕️ | | | | | | | | | | | | | | | |
| XieJunhua |||||| ⭕️ | | | | | | | | | | | | | | | |

<!-- END_COMMIT_TABLE -->


总之希望频率相同的人在 LXDAO 残酷氛围之下相互鼓励与学习交流,找到适合自己的英语精进节奏,加入进来试试吧。

Expand Down
82 changes: 82 additions & 0 deletions sync_status_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
from github import Github
from datetime import datetime, timedelta
import pytz

# 初始化GitHub API
g = Github(os.environ['GITHUB_TOKEN'])
repo = g.get_repo(os.environ['GITHUB_REPOSITORY'])

# 设置北京时区
beijing_tz = pytz.timezone('Asia/Shanghai')

# 获取所有贡献者
contributors = set(c.login for c in repo.get_contributors())

# 定义日期范围(从6月24日到7月14日)
start_date = datetime(2024, 6, 24, tzinfo=beijing_tz)
end_date = datetime(2024, 7, 14, tzinfo=beijing_tz)
date_range = [(start_date + timedelta(days=x)).strftime("%m.%d") for x in range((end_date - start_date).days + 1)]

# 获取当前北京时间
current_date = datetime.now(beijing_tz).replace(hour=0, minute=0, second=0, microsecond=0)

# 获取每个用户在每一天的提交状态
user_commits = {user: {} for user in contributors}
for date in date_range:
day = datetime.strptime(date, "%m.%d").replace(year=2024, tzinfo=beijing_tz)
if day >= current_date:
continue # 跳过今天及以后的日期
next_day = day + timedelta(days=1)
commits = repo.get_commits(since=day, until=next_day)
for commit in commits:
if commit.author:
user_commits[commit.author.login][date] = "✅"

# 检查是否有人在一周内超过两天没有提交
def check_weekly_status(user_commits, user, date):
week_start = datetime.strptime(date, "%m.%d").replace(year=2024, tzinfo=beijing_tz)
week_start -= timedelta(days=week_start.weekday()) # 调整到本周一
week_dates = [(week_start + timedelta(days=x)).strftime("%m.%d") for x in range(7)]
week_dates = [d for d in week_dates if d in date_range and d <= date]

missing_days = sum(1 for d in week_dates if user_commits[user].get(d, "⭕️") == "⭕️")
return "❌" if missing_days > 2 else user_commits[user].get(date, "⭕️")

# 生成新的表格内容
new_table = ['| EICL1st· Name | ' + ' | '.join(date_range) + ' |\n',
'| ------------- | ' + ' | '.join(['----' for _ in date_range]) + ' |\n']

for user in contributors:
row = f"| {user} |"
for date in date_range:
day = datetime.strptime(date, "%m.%d").replace(year=2024, tzinfo=beijing_tz)
if day >= current_date:
status = " " # 今天及以后的日期显示为空白
else:
status = check_weekly_status(user_commits, user, date)
row += f" {status} |"
new_table.append(row + '\n')

# 读取README.md文件
with open('README.md', 'r') as file:
content = file.read()

# 查找标记并替换内容
start_marker = "<!-- START_COMMIT_TABLE -->"
end_marker = "<!-- END_COMMIT_TABLE -->"
start_index = content.find(start_marker)
end_index = content.find(end_marker)

if start_index != -1 and end_index != -1:
new_content = (
content[:start_index + len(start_marker)] +
'\n' + ''.join(new_table) + '\n' +
content[end_index:]
)

# 写入更新后的内容
with open('README.md', 'w') as file:
file.write(new_content)
else:
print("Error: Couldn't find the table markers in README.md")

0 comments on commit ef996c1

Please sign in to comment.