Skip to content

Commit 36f4230

Browse files
committed
上传api
0 parents commit 36f4230

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

api/index.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: UTF-8 -*-
2+
import requests
3+
import re
4+
from http.server import BaseHTTPRequestHandler
5+
import json
6+
7+
gitpage = requests.get("https://github.com/Zfour")
8+
data = gitpage.text
9+
10+
contributionsreg = re.compile('<h2 class="f4 text-normal mb-2">(.*?)contributions')
11+
datadatereg = re.compile(r'data-date="(.*?)"/>')
12+
datacountreg = re.compile(r'data-count="(.*?)" data-date')
13+
14+
datadate = datadatereg.findall(data)
15+
datacount = datacountreg.findall(data)
16+
datacount =list(map(int, datacount))
17+
contributions = sum(datacount)
18+
19+
datalist=[]
20+
for index,item in enumerate(datadate):
21+
itemlist = {"date":item,"count":datacount[index]}
22+
datalist.append(itemlist)
23+
24+
returndata = {
25+
"tatal":contributions,
26+
"contributions":[
27+
datalist
28+
]
29+
30+
}
31+
32+
class handler(BaseHTTPRequestHandler):
33+
34+
def do_GET(self):
35+
self.send_response(200)
36+
self.send_header('Content-type','application/json')
37+
self.end_headers()
38+
self.wfile.write(json.dumps(returndata).encode('utf-8'))
39+
return

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2020.12.5
2+
chardet==4.0.0
3+
idna==2.10
4+
requests==2.25.1
5+
urllib3==1.26.2

0 commit comments

Comments
 (0)