File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77def list_split (items , n ):
88 return [items [i :i + n ] for i in range (0 , len (items ), n )]
9+
10+ # 安全转换字符串到整数,遇到无法转换的字符串返回0
11+ def safe_int_conversion (s ):
12+ try :
13+ return int (s )
14+ except ValueError :
15+ return 0
16+
917def getdata (name ):
1018 gitpage = requests .get ("https://github.com/" + name )
1119 data = gitpage .text
1220 datadatereg = re .compile (r'data-date="(.*?)" id="contribution-day-component' )
13- datacountreg = re .compile (r'<span class="sr-only">(.*?) contribution ' )
21+ datacountreg = re .compile (r'<tool-tip [^>]*>(\d+|No) contributions(?= on [^<]*</tool-tip>) ' )
1422 datadate = datadatereg .findall (data )
1523 datacount = datacountreg .findall (data )
16- datacount = list (map (int , [0 if i == "No" else i for i in datacount ]))
24+
25+ # 使用safe_int_conversion函数转换datacount中的每个项
26+ datacount = [safe_int_conversion (i ) for i in datacount ]
1727
1828 # 将datadate和datacount按照字典序排序
1929 sorted_data = sorted (zip (datadate , datacount ))
@@ -30,6 +40,7 @@ def getdata(name):
3040 "contributions" : datalistsplit
3141 }
3242 return returndata
43+
3344class handler (BaseHTTPRequestHandler ):
3445 def do_GET (self ):
3546 path = self .path
You can’t perform that action at this time.
0 commit comments