Skip to content

Commit 3637a93

Browse files
committed
.
1 parent 350d0e8 commit 3637a93

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vercel
2+
werkzeug*
3+
.history

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# 2022.9.4 公共域名墙了
1+
## 仓库简介
2+
3+
- 基于`Python`下的`gitcalendar`的自动获取apigithub日志
24

35
可以先使用https://gitcalendar.zfe.space/api
46
或者使用vecel的自定义域名绑定
@@ -81,3 +83,7 @@ https://github.com/Zfour/friends_link_list_api
8183
https://python-github-calendar-api-zfour.vercel.app/api/?zfour
8284

8385
如果显示数据则说明API配置成功。
86+
87+
## 感谢作者
88+
89+
- 来自[冰老师](https://github.com/Zfour/python_github_calendar_api)

api/index.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ def list_split(items, n):
99
def getdata(name):
1010
gitpage = requests.get("https://github.com/" + name)
1111
data = gitpage.text
12-
datadatereg = re.compile(r'data-date="(.*?)" data-level')
13-
datacountreg = re.compile(r'<span class="sr-only">(.*?) contribution')
12+
datadatereg = re.compile(r'data-date="(.*?)" id="contribution-day-component')
13+
14+
datacountreg = re.compile(r'<tool-tip .*?class="sr-only position-absolute">(.*?) contribution')
1415
datadate = datadatereg.findall(data)
1516
datacount = datacountreg.findall(data)
1617
datacount = list(map(int, [0 if i == "No" else i for i in datacount]))
1718

19+
# 检查datadate和datacount是否为空
20+
if not datadate or not datacount:
21+
# 处理空数据情况
22+
return {"total": 0, "contributions": []}
23+
1824
# 将datadate和datacount按照字典序排序
1925
sorted_data = sorted(zip(datadate, datacount))
2026
datadate, datacount = zip(*sorted_data)
21-
2227
contributions = sum(datacount)
2328
datalist = []
2429
for index, item in enumerate(datadate):

requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
certifi==2020.12.5
2-
chardet==4.0.0
3-
idna==2.10
4-
requests==2.25.1
5-
urllib3==1.26.2
1+
certifi==2023.11.17
2+
chardet==5.2.0
3+
idna==3.6
4+
requests==2.31.0
5+
urllib3==2.1.0

0 commit comments

Comments
 (0)