Skip to content

Commit e3f476a

Browse files
Add "diff" to json
1 parent 6f54f9a commit e3f476a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

generate.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232
generation_time = datetime.now(timezone.utc)
3333

3434

35+
def get_previous_completion(language_code: str) -> float:
36+
try:
37+
with open('index.json') as f:
38+
previous_data = json.load(f)
39+
for item in previous_data:
40+
if item['language']['code'] == language_code:
41+
return item.get('completion', 0.0)
42+
except FileNotFoundError:
43+
pass
44+
return 0.0
45+
46+
3547
def get_completion_progress() -> Iterator['LanguageProjectData']:
3648
with TemporaryDirectory() as clones_dir:
3749
Repo.clone_from(
@@ -76,6 +88,10 @@ def get_project_data(
7688
translators_data = TranslatorsData(0, False)
7789
visitors_num = 0
7890
branch = None
91+
92+
previous_completion = get_previous_completion(language.code)
93+
change = completion - previous_completion
94+
7995
return LanguageProjectData(
8096
language,
8197
repo,
@@ -87,6 +103,7 @@ def get_project_data(
87103
in_switcher=languages_built.get(language.code),
88104
uses_platform=language.code in contribute.pulling_from_transifex,
89105
contribution_link=contribute.get_contrib_link(language.code, repo),
106+
change=change,
90107
)
91108

92109

@@ -102,6 +119,7 @@ class LanguageProjectData:
102119
in_switcher: bool | None
103120
uses_platform: bool
104121
contribution_link: str | None
122+
change: float
105123

106124

107125
if __name__ == '__main__':
@@ -118,4 +136,4 @@ class LanguageProjectData:
118136
Path('index.html').write_text(output)
119137
Path('index.json').write_text(
120138
json.dumps(completion_progress, indent=2, default=asdict)
121-
)
139+
)

0 commit comments

Comments
 (0)