Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up topics vs practices in config.json #1421

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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