Skip to content

Commit

Permalink
Script to clean practices vs concepts
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Goodspeed-Niklaus <[email protected]>
  • Loading branch information
dmaahs2017 and coriolinus committed Jan 6, 2022
1 parent 86ed3c2 commit 40f5dbd
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 85 deletions.
42 changes: 42 additions & 0 deletions bin/clean_topics_vs_practices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
import json


def main():
with open("config.json", encoding="utf-8") as f:
config = json.load(f)

concepts = {c['slug'] for c in config['concepts']}

for practice_exercise in config['exercises']['practice']:
if practice_exercise['topics'] is None:
continue

practice_exercise['practices'].extend((topic for topic in practice_exercise['topics'] if topic in concepts))
practice_exercise['topics'] = [topic for topic in practice_exercise['topics'] if topic not in concepts]

for concept in concepts:
count = 0
for practice_exercise in config['exercises']['practice']:
if concept in practice_exercise['practices']:
count += 1
if count > 10:
practice_exercise['practices'].remove(concept)
practice_exercise['topics'].append(concept)

for practice_exercise in config['exercises']['practice']:
practice_exercise['practices'].sort()

if practice_exercise['topics'] is not None:
practice_exercise['topics'].sort()


with open("config.json", 'w', encoding="utf-8") as f:
json.dump(config, f, indent=2, ensure_ascii=False)
f.write('\n')

print("Updated config.json")


if __name__ == '__main__':
main()
Loading

0 comments on commit 40f5dbd

Please sign in to comment.