Skip to content

Commit 5b79019

Browse files
authored
fix reg
1 parent c95f5bb commit 5b79019

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

api/index.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ def getdata(name):
1010
gitpage = requests.get("https://github.com/" + name)
1111
data = gitpage.text
1212
datadatereg = re.compile(r'data-date="(.*?)" id="contribution-day-component')
13-
datacountreg = re.compile(r'<span class="sr-only">(.*?) contribution')
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]))
18+
19+
# 检查datadate和datacount是否为空
20+
if not datadate or not datacount:
21+
# 处理空数据情况
22+
return {"total": 0, "contributions": []}
23+
24+
# 将datadate和datacount按照字典序排序
25+
sorted_data = sorted(zip(datadate, datacount))
26+
datadate, datacount = zip(*sorted_data)
1727
contributions = sum(datacount)
1828
datalist = []
1929
for index, item in enumerate(datadate):

0 commit comments

Comments
 (0)