-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_readme.py
54 lines (43 loc) · 1.72 KB
/
update_readme.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
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
# @author = svaderia
# date = 05/04/2020
import subprocess
import os
import sys
from rich.console import Console
from rich.table import Table
def get_string(name, count):
return " * {} : {}".format(name + " " * (12 - len(name)), count)
def get_table(name, count):
return "|{} | {} |".format(name, count)
def main():
args = sys.argv
sol = (args[-1] == "solved")
folders = ["CodeChef", "CodeForces", "SPOJ", "AtCoder", "Leetcode", "Other", "15195"]
# if(sol) : folders.append("PEuler")
# TODO: make this a ENV variable
base = "/Users/svaderia/Shyamal/GitHub/competitive-programming"
readme_path = os.path.join(base, "README.md")
count = {f : int(subprocess.check_output("find -E {} -regex '.*/solution\.(cpp|py)' | wc -l".format(os.path.join(base, f)), shell=True)) for f in folders}
content = ""
total_solved = str(sum(count.values()))
if(sol):
table = Table(title="Solved Problems", show_footer=True)
table.add_column("Online Judge", "Total", style="italic")
table.add_column("Solved", total_solved, style="cyan")
for f in folders:
table.add_row(f, str(count[f]))
Console().print(table)
else:
with open(readme_path, "r") as f:
content = f.read()
content = content.split("# Competitive Programming\n")[0]
content += "# Competitive Programming\n"
content += "|Online Judge|Solved|\n"
content += "|------ | ------|\n"
content += " \n".join([get_table(f, count[f]) for f in folders])
content += " \n{}".format(get_table("Total", total_solved))
with open(readme_path, "w") as f:
f.write(content)
if __name__ == "__main__":
main()