Esempio n. 1
0
def getWeather():
    forecast = Forecastio("b8d1abd0c7da6a6c878e64015e78a8ee")
    result = forecast.load_forecast(39.960278,
                                    -74.978889,
                                    time=datetime.datetime.now(),
                                    units="si")

    if result['success'] is True:
        temp = (forecast.get_currently().temperature * 9.0 / 5.0) + 32
        return forecast.get_currently().summary
    else:
        return "FAIL"
Esempio n. 2
0
def get_weather(loc):
    location = location_list[loc]
    FORECASTIO_API_KEY = request.environ.get('FORECASTIO_API_KEY')
    forecast = Forecastio(FORECASTIO_API_KEY)
    result = forecast.load_forecast(location.latitude, location.longitude)
    current = forecast.get_currently()
    return '{"location": "%s", "temperature": "%.2f", "summary": "%s", "icon": "%s"}' % (loc, current.temperature, current.summary, current.icon.upper().replace("-", "_"))
Esempio n. 3
0
def main():
    forecast = Forecastio("dada3cbcc93a16056f865e34daec507a")

# Get Current weather
    result_current = forecast.load_forecast(40.4017,-74.0368,
                                   time=datetime.datetime.now(),units="si")

# Process weather data
    if result_current['success'] is True:
        byCurrent = forecast.get_currently()
        byMinute = forecast.get_minutely()
        byHour = forecast.get_hourly()
        byDay = forecast.get_daily()

    else:
        print "A problem occured communicating with the Forecast.io API"

# Print what we want, lining stuff up neatly
    print "Right Now: %-10s %s" % ("", byCurrent.summary)
    print "Next Hour: %-10s %s" % ("", byMinute.summary)
    print "Next 24 Hours: %-6s %s"  % ("", byHour.summary)
    print "Next 7 Days: %-8s %s" % ("", byDay.summary)


# Get us to our script folder so the link is created in the right place
    abspath = os.path.abspath(__file__)
    dname = os.path.dirname(abspath)
    os.chdir(dname)

# Get our icon and create the link. Go my most specific weather conditions.

    iconimg =  "None"
    if str(byCurrent.icon) == "None":
        if str(byMinute.icon) == "None":
            if str(byHour.icon) == "None":
                iconimg = byDay.icon
            else:
                iconimg = byHour.icon
        else:
            iconimg = str(byMinute.icon)
    else:
        iconimg = str(byCurrent.icon)

# Unlink the current image so it can be relinked or updated
    os.unlink("current.png")

    if iconimg == "clear-day":
        os.symlink("icons/Sun.png","current.png")

    if iconimg == "clear":
        os.symlink("icons/Sun.png","current.png")

    if iconimg == 'clear-night':
        os.symlink("icons/Moon.png","current.png")

    if iconimg == "rain":
        os.symlink("icons/Rain.png","current.png")

    if iconimg == 'snow':
        os.symlink("icons/Snow.png","current.png")

    if iconimg == 'sleet':
        os.symlink("icons/Sleet.png","current.png")

    if iconimg == 'wind':
        os.symlink("icons/Wind.png","current.png")

    if iconimg == 'fog':
        os.symlink("icons/Fog.png","current.png")

    if iconimg == "cloudy":
        os.symlink("icons/Cloud.png","current.png")

    if iconimg == 'partly-cloudy-day':
        os.symlink("icons/Cloud-Day.png","current.png")

    if iconimg == 'partly-cloudy-night':
        os.symlink("icons/Cloud-Night.png","current.png")
Esempio n. 4
0
city_long = -122.254110

# We can do real-time feed by passing the data directly into table
#Key generated by the API
forecast = Forecastio("8aa0dadbf2a543f28dca16c9304b678b")
result = forecast.load_forecast(city_lat, city_long)
#print result
#time duration for which we need the data
start_date = datetime.datetime(2015, 1, 1)
end_date = datetime.datetime(2015, 2, 28)
d = start_date
delta = datetime.timedelta(hours=1)
out = open('/Users/harshloomba/Documents/BlueBottle-Assignment/out1.csv', 'a')
while d <= end_date:
    result = forecast.load_forecast(city_lat, city_long, d, lazy=True)
    current = forecast.get_currently()
    days_list = []
    item = current
    time = item.time
    temperature = item.temperature
    #   print time.strftime("%Y-%m-%d %H:%M")
    #    print "%.2f" %temperature
    out.write(time.strftime("%Y-%m-%d %H:%M"))
    out.write(";")
    out.write("%.3f" % temperature)
    out.write('\n')
    d += delta
out.close()
print "sucessful"
#conn.commit()
city_long = -122.254110

# We can do real-time feed by passing the data directly into table
#Key generated by the API
forecast = Forecastio("8aa0dadbf2a543f28dca16c9304b678b")
result = forecast.load_forecast(city_lat,city_long)
#print result
#time duration for which we need the data
start_date = datetime.datetime(2015,1,1)
end_date = datetime.datetime(2015,2,28)
d = start_date
delta = datetime.timedelta(hours=1)
out = open('/Users/harshloomba/Documents/BlueBottle-Assignment/out1.csv', 'a')
while d <= end_date:
    result = forecast.load_forecast(city_lat,city_long,d,lazy=True)
    current = forecast.get_currently()
    days_list = []
    item = current
    time = item.time
    temperature = item.temperature
#   print time.strftime("%Y-%m-%d %H:%M")
#    print "%.2f" %temperature
    out.write(time.strftime("%Y-%m-%d %H:%M"))
    out.write(";")
    out.write("%.3f" %temperature)
    out.write('\n')
    d += delta
out.close()
print "sucessful"
#conn.commit()