Skip to content

Commit 5787cd7

Browse files
authored
Update index.py
1 parent bd595d0 commit 5787cd7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

api/index.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ def list_split(items, n):
99
def getdata(name):
1010
gitpage = requests.get("https://github.com/" + name)
1111
data = gitpage.text
12+
13+
# 2023-11-22 更新正则 https://github.com/Zfour/python_github_calendar_api/issues/18
1214
datadatereg = re.compile(r'data-date="(.*?)" id="contribution-day-component')
13-
datacountreg = re.compile(r'<span class="sr-only">(.*?) contribution')
15+
datacountreg = re.compile(r'<tool-tip .*?class="sr-only position-absolute">(.*?) contribution')
16+
1417
datadate = datadatereg.findall(data)
1518
datacount = datacountreg.findall(data)
1619
datacount = list(map(int, [0 if i == "No" else i for i in datacount]))
1720

21+
# 检查datadate和datacount是否为空
22+
if not datadate or not datacount:
23+
# 处理空数据情况
24+
return {"total": 0, "contributions": []}
25+
1826
# 将datadate和datacount按照字典序排序
1927
sorted_data = sorted(zip(datadate, datacount))
2028
datadate, datacount = zip(*sorted_data)
@@ -32,7 +40,9 @@ def getdata(name):
3240
return returndata
3341
class handler(BaseHTTPRequestHandler):
3442
def do_GET(self):
35-
path = self.path
43+
# 2024-02-21 固定用户名 https://github.com/Zfour/python_github_calendar_api/issues/20
44+
# path = self.path
45+
# user = path.split('?')[1]
3646
user = 'kahvia-d'
3747
data = getdata(user)
3848
self.send_response(200)

0 commit comments

Comments
 (0)