-
Notifications
You must be signed in to change notification settings - Fork 2
/
readme_gen.py
78 lines (45 loc) · 2.06 KB
/
readme_gen.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# code from https://github.com/l0k3ndr/log-of-learning/blob/master/readme_generator.py
import os
import re
from datetime import datetime
readme_file = open("README.md","w")
def override_print(x):
readme_file.write(x+"\n")
print = override_print
BLOB_PATH="https://github.com/...../notes"
mds = [ md for md in os.listdir("./notes/") if md.endswith(".md") ]
mds.remove('notes-dd-mmm-yyyy.md')
mds.sort(key = lambda date: datetime.strptime(date.split(".")[0].split("notes-")[1], '%d-%b-%Y'))
date_arr = []
categories = []
result = []
k = 1
last_type = None
for md in mds:
data = open("./notes/"+md).readlines()
temp_res = []
temp_content = []
for line in data:
if re.search("### \d+ - ", line.strip()):
temp_res += [ ("["+(line.strip().split(" - ",1)[1]).capitalize() + "]("+ BLOB_PATH + md + "#" + line.strip().lower().replace("###","")[1:].replace(" ","-").replace("?","").replace("(","").replace(")","").replace(",","").replace("_","") + ") ")]
date_arr += [md.split(".md")[0].split("notes-")[1]]
k = k+1
result += list(reversed(list(temp_res)))
prefix = """
_ __ _ _
| | ___ __ _ ___ / _| | | ___ __ _ _ __ _ __ (_) _ __ __ _
| | / _ \ / _` | _____ / _ \ | |_ _____ | | / _ \ / _` || '__|| '_ \ | || '_ \ / _` |
| || (_) || (_| ||_____|| (_) || _||_____|| || __/| (_| || | | | | || || | | || (_| |
|_| \___/ \__, | \___/ |_| |_| \___| \__,_||_| |_| |_||_||_| |_| \__, |
|___/ |___/
"""
prefix = "\n".join([" "*8+s for s in prefix.split("\n")]) +"\n"
prefix_sub = """
| LINK |
|------|"""
#print (prefix + "\n".join(list(reversed([ "|" + str(i+1)+"|" + result[i] + "|" + date_arr[i] + "|" for i in range(len(result))]))))
print( prefix)
print("[ "+ str(len(result)) + " ]")
print (prefix_sub)
print ( "\n".join(list(reversed([ "|" + result[i] + "|" for i in range(len(result))]))))
readme_file.close()