<commit_before>import json
import os
import django
import logging

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from unimeet.models import Country, City, University, School

level = logging.DEBUG
logger = logging.getLogger(__name__)
logger.setLevel(level)
logging.basicConfig(format='%(message)s')


def setup_schools(data):
    for country in data['countries']:
        country_obj = Country(name=country['name'])
        country_obj.save()
        logger.debug(country_obj.name)
        for city in country['cities']:
            city_obj = City(name=city['name'], country=country_obj)
            city_obj.save()
            logger.debug(2 * ' ' + city_obj.name)
            for university in city['universities']:
                university_obj = University(name=university['name'], city=city_obj)
                university_obj.save()
                logger.debug(4 * ' ' + university_obj.name)
                for school in university['schools']:
                    school_obj = School(name=school['name'], site=school['site'], mailRegex=school['mailRegex'], university=university_obj)
                    school_obj.save()
                    logger.debug(6 * ' ' + school_obj.name)

<commit_msg>Use get_or_create for db init<commit_after>import json
import os
import django
import logging

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from unimeet.models import Country, City, University, School

level = logging.DEBUG
logger = logging.getLogger(__name__)
logger.setLevel(level)
logging.basicConfig(format='%(message)s')


def setup_schools(data):
    for country in data['countries']:
        country_obj, created = Country.objects.get_or_create(name=country['name'])
        logger.debug(country_obj.name)
        for city in country['cities']:
            city_obj, created = City.objects.get_or_create(name=city['name'], country=country_obj)
            logger.debug(2 * ' ' + city_obj.name)
            for university in city['universities']:
                university_obj, created = University.objects.get_or_create(name=university['name'], city=city_obj)
                logger.debug(4 * ' ' + university_obj.name)
                for school in university['schools']:
                    school_obj, created = School.objects.get_or_create(name=school['name'], site=school['site'], mailRegex=school['mailRegex'], university=university_obj)
                    logger.debug(6 * ' ' + school_obj.name)


{'fraction_non_alphanumeric': 0.12104208416833667, 'fraction_numerical': 0.002404809619238477, 'mean_word_length': 3.2233502538071064, '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': '3720009', 'n_tokens_mistral': 719, 'n_tokens_neox': 708, 'n_words': 136}