Exemplo n.º 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)
Exemplo n.º 2
0
def test_sunrise_sunset(m):
    fullurl = 'http://api.wunderground.com/api/{}/astronomy/q/94101.json' \
        .format(my_secret_key)

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

    sunrise_sunset = SunriseSunset('94101')
    res = sunrise_sunset.run()

    assert res['sunrise_hour'] == "7"
    assert res['sunrise_min'] == "01"
    assert res['sunset_hour'] == "16"
    assert res['sunset_min'] == "56"