<commit_before>from django.core.management.base import BaseCommand, CommandError

from cities.google import google_places_api
from cities import data
from studygroups.models import StudyGroup

class Command(BaseCommand):
    help = 'Find lat, lon for study groups without a position defined'

    def handle(self, *args, **options):
        study_groups = StudyGroup.objects.active().filter(
            latitude__isnull=True,
            longitude__isnull=True,
        ).exclude(city='')
        for study_group in study_groups:
            #print(study_group.course.title, study_group.city)
            city_data = study_group.city.split(',')
            city = city_data[0].strip() if len(city_data) > 0 else None
            region = city_data[1].strip() if len(city_data) > 1 else None
            country = city_data[2].strip() if len(city_data) > 2 else None
            results = data.find_city(city, region, country)
            if len(results) == 0:
                print(u'Could not find any cities matching: ' + study_group.city)
                continue

            if len(results) > 1:
                print(u'Found more than one city matching: ' + study_group.city)
                for i, opt in enumerate([', '.join(cd[:3]) for cd in results]):
                    print(u'{}: {}'.format(i+1, opt))
                choice = raw_input('Please choose one: ')
                try:
                    choice = int(choice)-1
                    if choice > 0 and choice < len(results):
                        results = [results[choice]]
                except ValueError as e:
                    continue

            if len(results) <> 1:
                continue

            print(u'update location for {}, lat={}, lon={}'.format(study_group.city, results[0][3], results[0][4]))
            study_group.latitude = results[0][3]
            study_group.longitude = results[0][4]
            study_group.save()

            #response = google_places_api(study_group.city)
            #results = response['results']
            #location = results[0]['geometry']['location']
            #study_group.latitude = location['lat']
            #study_group.longitude = location['lng']<commit_msg>fix utf-8 errors<commit_after>from django.core.management.base import BaseCommand, CommandError

from cities.google import google_places_api
from cities import data
from studygroups.models import StudyGroup

class Command(BaseCommand):
    help = 'Find lat, lon for study groups without a position defined'

    def handle(self, *args, **options):
        study_groups = StudyGroup.objects.active().filter(
            latitude__isnull=True,
            longitude__isnull=True,
        ).exclude(city='')
        for study_group in study_groups:
            #print(study_group.course.title, study_group.city)
            city_data = study_group.city.split(',')
            city = city_data[0].strip() if len(city_data) > 0 else None
            region = city_data[1].strip() if len(city_data) > 1 else None
            country = city_data[2].strip() if len(city_data) > 2 else None
            results = data.find_city(city, region, country)
            if len(results) == 0:
                print(u'Could not find any cities matching: {}'.format(study_group.city))
                continue

            if len(results) > 1:
                print(u'Found more than one city matching: {}'.format(study_group.city))
                for i, opt in enumerate([u', '.join(cd[:3]) for cd in results]):
                    print(u'{}: {}'.format(i+1, opt))
                choice = raw_input('Please choose one: ')
                try:
                    choice = int(choice)-1
                    if choice > 0 and choice < len(results):
                        results = [results[choice]]
                except ValueError as e:
                    continue

            if len(results) <> 1:
                continue

            print(u'update location for {}, lat={}, lon={}'.format(study_group.city, results[0][3], results[0][4]))
            study_group.latitude = results[0][3]
            study_group.longitude = results[0][4]
            study_group.save()

            #response = google_places_api(study_group.city)
            #results = response['results']
            #location = results[0]['geometry']['location']
            #study_group.latitude = location['lat']
            #study_group.longitude = location['lng']
{'fraction_non_alphanumeric': 0.11479476770410464, 'fraction_numerical': 0.010148849797023005, 'mean_word_length': 2.0586206896551724, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3226385', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1169, 'n_words': 305}