Skip to content

Commit

Permalink
2023-07-20 针对07-15更新了正则,并按字典序排序
Browse files Browse the repository at this point in the history
Zfour/python_github_calendar_api#15

ShengQiBaoZao:23-07-15日github更新后,原先的正则错误,更新了正则,并按字典序排序 

Barry-Flynn:请问那两个变量为什么要按照字典排序呢?

ShengQiBaoZao:您好,可以看一下github更新后的网页源代码,爬虫爬下来的顺序变成了按照星期几排列,比如先从22年,比如7月4号-11号-18号这样一直到23年的星期一排列完成,然后再从22年星期二排列,对于当前calendar呈现出来也会是这样的顺序,所以要按照datadate进行字典排序
  • Loading branch information
Barry-Flynn authored Jul 20, 2023
1 parent b45e1d2 commit 7653ffa
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ def getdata(name):
gitpage = requests.get("https://github.com/" + name)
data = gitpage.text
datadatereg = re.compile(r'data-date="(.*?)" data-level')
# 注释掉原有正则,更新新的正则使其可以继续使用 https://github.com/Zfour/python_github_calendar_api/pull/5
# datacountreg = re.compile(r'data-count="(.*?)" data-date')
datacountreg = re.compile(r'rx="2" ry="2">(.*?) contribution')
# 针对2023-07-15更新了正则,并按字典序排序 https://github.com/Zfour/python_github_calendar_api/pull/15
datacountreg = re.compile(r'<span class="sr-only">(.*?) contribution')
datadate = datadatereg.findall(data)
datacount = datacountreg.findall(data)
# datacount = list(map(int, datacount))
datacount = list(map(int, [0 if i == "No" else i for i in datacount]))

# 将datadate和datacount按照字典序排序
sorted_data = sorted(zip(datadate, datacount))
datadate, datacount = zip(*sorted_data)

contributions = sum(datacount)
datalist = []
for index, item in enumerate(datadate):
Expand Down

1 comment on commit 7653ffa

@vercel
Copy link

@vercel vercel bot commented on 7653ffa Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.