Skip to content

Commit dd1ec66

Browse files
JskobosGuessWhoSamFoo
authored andcommitted
Add script for identifying old non-deprecated guides (#1394)
1 parent d2f52ce commit dd1ec66

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

ci/old_guides.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from tabulate import tabulate
2+
from operator import itemgetter
3+
import yaml
4+
import regex
5+
import glob
6+
7+
def parse_yaml(filestring):
8+
reg = regex.compile(r'^---(.*?)---',flags=regex.DOTALL)
9+
match = regex.search(reg, filestring)
10+
if not match: return {}
11+
yaml_text = match.group(1)
12+
try:
13+
return yaml.load(yaml_text)
14+
except:
15+
return {}
16+
17+
def make_record(yaml):
18+
if 'title' in yaml:
19+
title = yaml['title']
20+
else:
21+
title = "No title"
22+
record = {
23+
'title': title,
24+
'updated': yaml['modified']
25+
}
26+
return record
27+
28+
29+
def find_old_guides():
30+
old_guides = []
31+
guides_scanned = 0
32+
rootdir = 'docs'
33+
for files in glob.glob('docs/**/*.md',recursive=True):
34+
guides_scanned += 1
35+
filename = files
36+
with open(filename, 'r') as f:
37+
filestring = f.read()
38+
parsed = parse_yaml(filestring)
39+
if 'modified' in parsed and 'deprecated' not in parsed:
40+
record = make_record(parsed)
41+
record['path'] = filename
42+
old_guides.append(record)
43+
print(str(guides_scanned) + " guides scanned.")
44+
old_guides.sort(key=itemgetter('updated'))
45+
oldest_guides = old_guides[0:20]
46+
print(tabulate(oldest_guides))
47+
48+
49+
if __name__ == '__main__':
50+
find_old_guides()

0 commit comments

Comments
 (0)