<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import json
import os
import re
import sys
import urllib

from clint.textui import puts, colored


class WeatherDataError(Exception):
    pass


class Weather(object):
    def now(self, query):
        raw_data = urllib.urlopen('http://api.openweathermap.org/data/2.5/weather?q={0}&units=imperial'.format(urllib.quote_plus(query))).read()
        
        try:
            weather = json.loads(raw_data)
        except ValueError:
            raise WeatherDataError("Malformed response from weather service")

        try:
            temperature = int(weather['main']['temp'])
            condition = weather['weather'][0]['description']
        except KeyError:
            raise WeatherDataError("No conditions reported for your search")

        return u"It's {0}\u00B0 and {1}".format(temperature, condition.lower())


def get_temp_color(conditions):
    temp_color_map = [
        (40, 'cyan'),
        (60, 'blue'),
        (80, 'yellow')
    ]
        
    temperature_re = re.compile('(?P<temperature>-?\d+)')
    match = temperature_re.search(conditions)
    if match:
        for color in temp_color_map:
            if int(match.group('temperature')) <= color[0]:
                return color[1]
        return 'red'
    return 'white'
    

def main():
    parser = argparse.ArgumentParser(description="Outputs the weather for a given location query string")
    parser.add_argument('query', metavar='query', nargs="?", help="A location query string to find weather for")

    args = parser.parse_args()
    weather = Weather()

    query = os.environ.get('WEATHER', args.query)
    if not query:
        parser.print_help()
        sys.exit(1)<commit_msg>Command line query should override env var<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import json
import os
import re
import sys
import urllib

from clint.textui import puts, colored


class WeatherDataError(Exception):
    pass


class Weather(object):
    def now(self, query):
        raw_data = urllib.urlopen('http://api.openweathermap.org/data/2.5/weather?q={0}&units=imperial'.format(urllib.quote_plus(query))).read()
        
        try:
            weather = json.loads(raw_data)
        except ValueError:
            raise WeatherDataError("Malformed response from weather service")

        try:
            temperature = int(weather['main']['temp'])
            condition = weather['weather'][0]['description']
        except KeyError:
            raise WeatherDataError("No conditions reported for your search")

        return u"It's {0}\u00B0 and {1}".format(temperature, condition.lower())


def get_temp_color(conditions):
    temp_color_map = [
        (40, 'cyan'),
        (60, 'blue'),
        (80, 'yellow')
    ]
        
    temperature_re = re.compile('(?P<temperature>-?\d+)')
    match = temperature_re.search(conditions)
    if match:
        for color in temp_color_map:
            if int(match.group('temperature')) <= color[0]:
                return color[1]
        return 'red'
    return 'white'
    

def main():
    parser = argparse.ArgumentParser(description="Outputs the weather for a given location query string")
    parser.add_argument('query', metavar='query', nargs="?", help="A location query string to find weather for")

    args = parser.parse_args()
    weather = Weather()

    query = args.query or os.environ.get('WEATHER')
    if not query:
        parser.print_help()
        sys.exit(1)
{'fraction_non_alphanumeric': 0.12744819755889866, 'fraction_numerical': 0.010786261708770934, 'mean_word_length': 2.781115879828326, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1945289', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1017, 'n_words': 256}