-
Notifications
You must be signed in to change notification settings - Fork 0
/
contributions.py
42 lines (32 loc) · 888 Bytes
/
contributions.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
#
# Print your contributions for the current day
# Usage: ghb contributions
#
import html.parser
import requests
from .helpers import credentials
URL = "https://github.com/users/%s/contributions"
class CustomHTMLParser(html.parser.HTMLParser):
def __init__(self):
html.parser.HTMLParser.__init__(self)
self.rects = []
def handle_starttag(self, tag, attrs):
if tag == "rect":
self.rects.append(attrs)
def pluralize(number):
if number == 1:
return ""
return "s"
def main(_):
username, _ = credentials.credentials()
r = requests.get(URL % username)
parser = CustomHTMLParser()
parser.feed(r.text)
d = dict(parser.rects[-1])
number = d["data-count"]
date = d["data-date"]
print(
"You have {} contribution{} on {}".format(
number, pluralize(number), date
)
)