File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments