<commit_before>from django.conf import settings
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt

import requests


class CsrfExemptMixin(object):
    @method_decorator(csrf_exempt)
    def dispatch(self, *args, **kwargs):
        return super(CsrfExemptMixin, self).dispatch(*args, **kwargs)


class WeatherFormMixin(object):
    def get_geocode(self, address):
        key = settings.GOOGLE_GEOCODING_API_KEY
        url = 'https://maps.googleapis.com/maps/api/geocode/json'
        r = requests.get(url, params={'address': address, 'key': key})
        j = r.json()
        if j['status'] == 'OK':
            return j['results'][0]
        else:
            errors = {
                'zero_results': 'We\u2019re sorry, but we could not find %s.' % address,
                'over_query_limit': 'We\u2019re sorry, but the request quota has been reached.',
                'request_denied': 'We\u2019re sorry, but the request was denied.',
                'invalid_request': 'We\u2019re sorry, but the request was invalid.',
                'unknown': 'We\u2019re sorry, but an error occurred.',
            }
            try:
                return errors[j['status'].lower()]
            except KeyError:
                return errors['unknown']

    def get_weather(self, geocode):
        key = settings.DARK_SKY_API_KEY
        latitude = geocode['geometry']['location']['lat']
        longitude = geocode['geometry']['location']['lng']
        units = 'us'
        url = 'https://api.darksky.net/forecast/%s/%s,%s' % (key, latitude, longitude)
        r = requests.get(url, params={'units': units})
        return r.json()

    def get_results(self, address):
        results = {}
        geocode = self.get_geocode(address)
        if isinstance(geocode, str):
            results['error'] = geocode
        else:
            results['geocode'] = geocode
            results['weather'] = self.get_weather(geocode)<commit_msg>Changed units to auto, fixes #1<commit_after>from django.conf import settings
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt

import requests


class CsrfExemptMixin(object):
    @method_decorator(csrf_exempt)
    def dispatch(self, *args, **kwargs):
        return super(CsrfExemptMixin, self).dispatch(*args, **kwargs)


class WeatherFormMixin(object):
    def get_geocode(self, address):
        key = settings.GOOGLE_GEOCODING_API_KEY
        url = 'https://maps.googleapis.com/maps/api/geocode/json'
        r = requests.get(url, params={'address': address, 'key': key})
        j = r.json()
        if j['status'] == 'OK':
            return j['results'][0]
        else:
            errors = {
                'zero_results': 'We\u2019re sorry, but we could not find %s.' % address,
                'over_query_limit': 'We\u2019re sorry, but the request quota has been reached.',
                'request_denied': 'We\u2019re sorry, but the request was denied.',
                'invalid_request': 'We\u2019re sorry, but the request was invalid.',
                'unknown': 'We\u2019re sorry, but an error occurred.',
            }
            try:
                return errors[j['status'].lower()]
            except KeyError:
                return errors['unknown']

    def get_weather(self, geocode):
        key = settings.DARK_SKY_API_KEY
        latitude = geocode['geometry']['location']['lat']
        longitude = geocode['geometry']['location']['lng']
        units = 'auto'
        url = 'https://api.darksky.net/forecast/%s/%s,%s' % (key, latitude, longitude)
        r = requests.get(url, params={'units': units})
        return r.json()

    def get_results(self, address):
        results = {}
        geocode = self.get_geocode(address)
        if isinstance(geocode, str):
            results['error'] = geocode
        else:
            results['geocode'] = geocode
            results['weather'] = self.get_weather(geocode)
{'fraction_non_alphanumeric': 0.12893553223388307, 'fraction_numerical': 0.01074462768615692, 'mean_word_length': 2.444922547332186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '955460', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1174, 'n_words': 278}