GitHub贡献图api
This Serverless Function has crashed.
Your connection is working correctly.
Vercel is working correctly.
500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED
ID: hkg1::crjjw-1691212510196-1a44a38e168c
GitHub仓库 {#GitHub仓库}
https://github.com/Zfour/python_github_calendar_api
问题原因 {#问题原因}
github更新,更新正则匹配就行 。
操作 {#操作}
具体部署步骤看教程即可
fork到自己仓库后之需要更改api/index.py文件即可
改为
|---------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| # -*- coding: UTF-8 -*- import requests import re from http.server import BaseHTTPRequestHandler import json def list_split(items, n): return [items[i:i + n] for i in range(0, len(items), n)] def getdata(name): gitpage = requests.get("https://github.com/" + name) data = gitpage.text datadatereg = re.compile(r'data-date="(.*?)" data-level') datacountreg = re.compile(r'<span class="sr-only">(.*?) contribution') datadate = datadatereg.findall(data) datacount = datacountreg.findall(data) 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): itemlist = {"date": item, "count": datacount[index]} datalist.append(itemlist) datalistsplit = list_split(datalist, 7) returndata = { "total": contributions, "contributions": datalistsplit } return returndata class handler(BaseHTTPRequestHandler): def do_GET(self): path = self.path user = path.split('?')[1] data = getdata(user) self.send_response(200) self.send_header('Access-Control-Allow-Origin', '*') self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(json.dumps(data).encode('utf-8')) return
|
图示 {#图示}
如有其他问题 {#如有其他问题}
欢迎评论区留言
或加入群聊一起交流学习