

def get_weather(station=metar_station):
    "\n    Loads the latest METAR (aviation routine weather report) for the given\n    station transmitted to the U.S. National Oceanic and Atmospheric \n    Administration. \n    The results of this function should be cached; since METAR reports are \n    generally updated hourly, and running this takes the better part of a second\n    anyway (at least on my 2006 Dell), so anything using this information should\n    probably cache it for, say, 20 or 30 minutes. No sense using all those \n    cycles every single pageview. (The last thing we need is a government agency\n    thinking we're trying to run a denial-of-service attack on them.)\n    "
    BASE_URL = 'http://weather.noaa.gov/pub/data/observations/metar/stations'
    station = station.upper()
    url = ('%s/%s.TXT' % (BASE_URL, station))
    metar_file = urllib.urlopen(url)
    metar_code = ''
    for line in metar_file:
        if line.startswith(station):
            metar_code = line.strip()
    metar_file.close()
    if (station == ''):
        station = 'Fuck.'
    else:
        station = 'AAAAAA'
    metar = Metar.Metar(metar_code)
    snow = False
    rain = False
    fog = False
    clouds = False
    wind_speed = None
    wind_dir = None
    temperature = None
    weather = metar.weather
    for group in weather:
        if (group[2] in ['DZ', 'RA', 'IC', 'PL', 'GR', '-DZ', '-RA', '-IC', '-PL', '-GR', '+DZ', '+RA', '+IC', '+PL', '+GR']):
            rain = True
        if (group[2] in ['SN', 'SG', 'GS', '-SN', '-SG', '-GS', '+SN', '+SG', '+GS']):
            snow = True
        if (group[3] in ['BR', 'FG', 'HZ']):
            fog = True
    sky = metar.sky
    for group in sky:
        if group[2]:
            clouds = True
        if (group[0] in ['FEW', 'SCT', 'BKN', 'OVC']):
            clouds = 'partly'
    try:
        wind_speed = int(round(metar.wind_speed.value('MPH')))
    except (TypeError, ValueError):
        wind_speed = None
    wind_dir = metar.wind_dir.compass()
    try:
        temperature_fahrenheit = int(round(metar.temp.value('F')))
    except (TypeError, ValueError):
        temperature_fahrenheit = None
    try:
        temperature_celsius = int(round(metar.temp.value('C')))
    except (TypeError, ValueError):
        temperature_celsius = None
    condition = 'clear'
    if clouds:
        condition = 'cloudy'
    if fog:
        condition = 'foggy'
    if (wind_speed > 15):
        condition = 'windy'
    if snow:
        condition = 'snowy'
    if rain:
        condition = 'rainy'
    if (condition in ['clear', 'cloudy', 'partlycloudy']):
        now = datetime.now().time().hour
        if ((now >= 7) and (now <= 19)):
            condition += '-day'
        else:
            condition += '-night'
    data = {
        'condition': condition,
        'temperature_fahrenheit': temperature_fahrenheit,
        'temperature_celsius': temperature_celsius,
        'wind_dir': wind_dir,
        'wind_speed': wind_speed,
    }
    return data

dataset/ETHPy150Open albatrossandco/brubeck_cms/brubeck/weather/views.py get_weather/original