Example #1
0
def weather():
    zipcode = get_zipcode()

    output = ''

    conditions = CurrentConditions(zipcode)
    cc = conditions.run()

    output += '\n\nWeather for {} ({})\n\n'.format(zipcode, cc['city_state'])
    output += 'Current weather: {}˚F, {}\n'.format(cc['curr_temp'],
                                                    cc['curr_weather'])

    sunrise_sunset = SunriseSunset(zipcode)
    ss = sunrise_sunset.run()

    output += 'Sunrise {}:{}, Sunset {}:{}\n\n'.format(
        ss['sunrise_hour'], ss['sunrise_min'],
        ss['sunset_hour'], ss['sunset_min']
    )

    ten_day = TenDay(zipcode)
    td = ten_day.run()

    output += '10-day Forecast:\n'

    for n in range(1, 11):
        day = 'day' + str(n)
        output += '{}: High {}˚F, Low {}˚F, {}\n'.format(
            td[day], td[day + '_high'], td[day + '_low'],
            td[day + '_conditions'])

    weather_alerts = WeatherAlerts(zipcode)
    we_al = weather_alerts.run()

    if len(we_al) > 0:
        output += '\n\nAlerts:\n'
        for n, alert in enumerate(we_al):
            a = 'alert' + str(n + 1)
            output += '{}\nIssued: {}\nExpires: {}\n'.format(
                alert[0][a], alert[a + '_start'], alert[a + '_end']
            )



    hurricanes = ActiveHurricanes()
    hur = hurricanes.run()

    if len(hur) > 0:
        output += '\n\nCurrent Hurricanes:\n'
        for n in range(len(hur)):
            output += 'Storm: {}, Category: {}\n'.format(
                hur[n]['hurricane_name'], hur[n]['hurricane_category']
            )


    print(output)
Example #2
0
def test_ten_day(m):
    fullurl = 'http://api.wunderground.com/api/{}/forecast10day/q/94101.json' \
        .format(my_secret_key)

    with open('json-data/ten-day.json') as data:
        m.get(fullurl, text=data.read())

    ten_day = TenDay('94101')
    res = ten_day.run()

    assert res['day1'] == "Tue"
    assert res['day1_high'] == "75"
    assert res['day1_low'] == "55"
    assert res['day1_conditions'] == "Partly Cloudy"
    assert res['day2'] == "Wed"
    assert res['day2_high'] == "72"
    assert res['day2_low'] == "55"
    assert res['day2_conditions'] == "Partly Cloudy"
    assert res['day3_high'] == "70"
    assert res['day3_low'] == "55"
    assert res['day3_conditions'] == "Partly Cloudy"
    assert res['day4_high'] == "72"
    assert res['day4_low'] == "55"
    assert res['day4_conditions'] == "Partly Cloudy"
    assert res['day5_high'] == "73"
    assert res['day5_low'] == "55"
    assert res['day5_conditions'] == "Fog"
    assert res['day6_high'] == "72"
    assert res['day6_low'] == "55"
    assert res['day6_conditions'] == "Fog"
    assert res['day7_high'] == "70"
    assert res['day7_low'] == "55"
    assert res['day7_conditions'] == "Partly Cloudy"
    assert res['day8_high'] == "75"
    assert res['day8_low'] == "59"
    assert res['day8_conditions'] == "Partly Cloudy"
    assert res['day9_high'] == "73"
    assert res['day9_low'] == "59"
    assert res['day9_conditions'] == "Partly Cloudy"
    assert res['day10_high'] == "73"
    assert res['day10_low'] == "57"
    assert res['day10_conditions'] == "Clear"