Skip to content

Commit 0e7407e

Browse files
committed
update msg
1 parent ba41c4d commit 0e7407e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

api/index.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@
77
def list_split(items, n):
88
return [items[i:i + n] for i in range(0, len(items), n)]
99
def getdata(name):
10-
gitpage = requests.get("https://github.com/" + name)
10+
# 2024-03-29 定义 headers 请求头
11+
# 请见 https://github.com/yuhengwei2001/python_github_calendar_api/commit/0f37cfc003f09e99a1892602d8bc2b38137899d2#diff-b014e93fcab9bae29f453d7a616da5eac2f02947f32d02a1a1bf200eeaab5a39L11
12+
headers = {
13+
'Referer': 'https://github.com/'+ name,
14+
'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"',
15+
'Sec-Ch-Ua-Mobile': '?0',
16+
'Sec-Ch-Ua-Platform': '"Windows"',
17+
'Sec-Fetch-Dest': 'empty',
18+
'Sec-Fetch-Mode': 'cors',
19+
'Sec-Fetch-Site': 'same-origin',
20+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0',
21+
'X-Requested-With': 'XMLHttpRequest'
22+
}
23+
# 发送请求时添加 headers 请求头
24+
#gitpage = requests.get("https://github.com/" + name)
25+
gitpage = requests.get("https://github.com/" + name + "?action=show&controller=profiles&tab=contributions&user_id="+ name, headers=headers)
1126
data = gitpage.text
1227
datadatereg = re.compile(r'data-date="(.*?)" id="contribution-day-component')
1328
datacountreg = re.compile(r'<tool-tip .*?class="sr-only position-absolute">(.*?) contribution')
@@ -46,3 +61,9 @@ def do_GET(self):
4661
self.end_headers()
4762
self.wfile.write(json.dumps(data).encode('utf-8'))
4863
return
64+
65+
if __name__ == '__main__':
66+
from http.server import HTTPServer
67+
server = HTTPServer(('localhost', 8080), handler)
68+
while True:
69+
server.handle_request()

0 commit comments

Comments
 (0)