-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
46 lines (38 loc) · 1.28 KB
/
script.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
import subprocess, json
import git
def script():
repo_path = '/docs/'
# docs_path = '/docs/src/docs'
# md_suffix = re.compile(".*md$")
# update railway docs repo
repo = git.cmd.Git(repo_path)
repo.pull()
all_files = []
export = []
values = []
# search through docs, find markdown files, and calculate score
# for root, _, files in os.walk(docs_path, topdown=False):
# for file in files:
# if re.match(md_suffix, file):
# path = os.path.join(root, file)
# output = pypandoc.convert_file(path, 'plain')
# analysis = Readability(output)
# flesch = analysis.flesch()
# response = {path: flesch.score}
# export.append(response)
# values.append(flesch.score)
# all_files.append(flesch)
args = ['/usr/bin/vale', '/docs/src/docs', '--config=./vale.ini', '--output=JSON']
p = subprocess.check_output(args)
data = json.loads(p)
for key, value in data.items():
response = {key: value[0]['Message']}
export.append(response)
values.append(float(value[0]['Message']))
# reduce values to one sum, count the docs, find overall average, and append to results
values_sum = sum(values)
docs_sum = len(export)
flesch_average = values_sum / docs_sum
export.append({'flesch_average': flesch_average})
export.append({'docs_sum': docs_sum})
return export