Skip to content

Commit 77634cd

Browse files
committed
more chanfes
1 parent 9cdb949 commit 77634cd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

check_loc.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import json
2+
import sys
3+
from github import Github
4+
from subprocess import Popen, PIPE
5+
import os
6+
if len(sys.argv) != 2:
7+
print(f"Usage: {sys.argv[0]} <github token>")
8+
sys.exit(1)
9+
10+
os.system("git switch main")
11+
12+
t = Popen(["tokei", "--output=json"], stdout=PIPE, stderr=PIPE)
13+
14+
stdout, stderr = t.communicate()
15+
if stderr:
16+
print(f"Error: {stderr}")
17+
sys.exit(1)
18+
19+
t = json.loads(stdout),
20+
code = int(t[0]['Total']['code'])
21+
blanks = int(t[0]['Total']['blanks'])
22+
comments = int(t[0]['Total']['comments'])
23+
count = code + blanks + comments
24+
25+
print(f"Total: {count}")
26+
27+
# upload the results to github
28+
# with this format: {"schemaVersion":1,"label":"Crates.io Total Downloads","message":"0","color":"black"}
29+
base64_json = {"schemaVersion":1,"label":"Total Lines of Code","message":f"{count}","color":"black"}
30+
base64_json = json.dumps(base64_json)
31+
32+
# using an access token
33+
g = Github(sys.argv[1])
34+
35+
# get last sha
36+
git = g.get_repo("mendelsshop/git_function_history")
37+
commit = git.get_contents("loc.json", ref="stats")
38+
39+
# update the file
40+
git.update_file("stats/loc.json", "update loc.json", base64_json, commit.sha)
41+
42+
os.system("git switch stats")

0 commit comments

Comments
 (0)