<commit_before>from .load_data_from_file import load_data_from_file
from .save_data import save_data
from .paths import mappings_path
import json
import os


def maintain_lists_of_entries(all_courses):
    data_sets = {
        'departments': set(),
        'instructors': set(),
        'times': set(),
        'locations': set(),
        'gereqs': set(),
        'types': set(),
    }

    for key in data_sets:
        filename = os.path.join(mappings_path, 'valid_%s.json' % key)
        data = load_data_from_file(filename)
        data_sets[key] = set(json.loads(data)[key])

    for course in all_courses:
        data_sets['departments'].update(course.get('depts', []))
        data_sets['instructors'].update(course.get('instructors', []))
        data_sets['times'].update(course.get('times', []))
        data_sets['locations'].update(course.get('places', []))
        data_sets['gereqs'].update(course.get('gereqs', []))
        data_sets['types'].add(course.get('type', ''))

    for key in data_sets:
        data_sets[key] = sorted(data_sets[key])

    for key, data in data_sets.items():
        filename = os.path.join(mappings_path, 'valid_%s.json' % key)
        json_data = json.dumps({key: data},
                               indent='\t', separators=(',', ': '))
        save_data(json_data, filename)<commit_msg>simplify the saving/loading of the lists<commit_after>from .load_data_from_file import load_data_from_file
from .save_data import save_data
from .paths import mappings_path
import json
import os


def maintain_lists_of_entries(all_courses):
    data_sets = {
        'departments': set(),
        'instructors': set(),
        'times': set(),
        'locations': set(),
        'gereqs': set(),
        'types': set(),
    }

    for key in data_sets:
        filename = os.path.join(mappings_path, 'valid_%s.json' % key)
        data = load_data_from_file(filename)
        data_sets[key] = set(json.loads(data))

    for course in all_courses:
        data_sets['departments'].update(course.get('depts', []))
        data_sets['instructors'].update(course.get('instructors', []))
        data_sets['times'].update(course.get('times', []))
        data_sets['locations'].update(course.get('places', []))
        data_sets['gereqs'].update(course.get('gereqs', []))
        data_sets['types'].add(course.get('type', ''))

    for key in data_sets:
        data_sets[key] = sorted(data_sets[key])

    for key, data in data_sets.items():
        filename = os.path.join(mappings_path, 'valid_%s.json' % key)
        json_data = json.dumps(data, indent='\t', separators=(',', ': '))
        save_data(json_data + '\n', filename)
{'fraction_non_alphanumeric': 0.1607209913631243, 'fraction_numerical': 0.0, 'mean_word_length': 3.1625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7566973', 'n_tokens_mistral': 882, 'n_tokens_neox': 859, 'n_words': 154}