-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse.py
35 lines (25 loc) · 1.21 KB
/
parse.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
from bs4 import BeautifulSoup
import requests as req
def loadPage(username, year):
resp = req.get("https://github.com/{0}?tab=overview&from={1}-01-01&to={1}-12-31".format(username, year))
soup = BeautifulSoup(resp.text, 'lxml')
return soup
#-------------------------------------------------------------------------------
def parseSimpleYear(username, year):
resp = req.get("https://github.com/{0}?tab=overview&from={1}-01-01&to={1}-12-31".format(username, year))
soup = BeautifulSoup(resp.text, 'lxml')
#print("read page: \"{0}\" ({1})".format(soup.title.text, year))
text = soup.find('h2', 'f4 text-normal mb-2').text.strip()
text = text.replace(',','')
commits = int(text.split()[0])
return commits
#-------------------------------------------------------------------------------
dates = []
counts = []
def parseFullYear(username, year):
resp = req.get("https://github.com/{0}?tab=overview&from={1}-01-01&to={1}-12-31".format(username, year))
soup = BeautifulSoup(resp.text, 'lxml')
for tag in soup.find_all("rect", "day"):
#print("Date: {0}, Count: {1}".format(tag["data-date"], tag["data-count"]))
dates.append(tag["data-date"])
counts.append(tag["data-count"])