本文整理汇总了Python中forecastio.load_forecast方法的典型用法代码示例。如果您正苦于以下问题:Python forecastio.load_forecast方法的具体用法?Python forecastio.load_forecast怎么用?Python forecastio.load_forecast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forecastio
的用法示例。
在下文中一共展示了forecastio.load_forecast方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_weather_data
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def get_weather_data(self, lat_lng_tuple, **keyword_parameters):
"""
:param lat_lng_tuple: (Latitude, Longitude)
:return: A forcastioDataBlock with a location's weather
"""
if 'date_offset' in keyword_parameters:
date_offset = keyword_parameters['date_offset']
else:
date_offset = 0
current_tz_id = self.location.parse_timezone(self.location.get_timezone(lat_lng_tuple))
utc = pytz.utc
utc_dt = utc.localize(datetime.datetime.utcnow())
current_timezone = timezone(current_tz_id)
current_dt = current_timezone.normalize(utc_dt.astimezone(current_timezone))
requested_date = current_dt + timedelta(days=date_offset)
forecast = forecastio.load_forecast(os.environ.get('DARK_SKY_API_KEY'), lat_lng_tuple[0], lat_lng_tuple[1],
time=requested_date, units="us")
return forecast
示例2: calculate
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def calculate():
current_time = datetime.datetime.now()
forecast = forecastio.load_forecast(api_key, lat, lng)
current = forecast.currently()
addres = getaddress()
print
print("Adress : " + addres)
print
t = PrettyTable(['Variable', 'Value'])
t.add_row(['Latitud', str(lat)])
t.add_row(["longitud:", str(lng)])
t.add_row(["sumary: ", str(current.summary)])
t.add_row(["icon: ", str(current.icon)])
t.add_row(["temperature: ", str(current.temperature)])
t.add_row(["humidity: ", str(current.humidity)])
t.add_row(["preassure: ", str(current.pressure)])
t.add_row(["ozone: ", str(current.ozone)])
t.add_row(["date-time: ", str(current_time)])
print t
return forecast
示例3: forecast
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def forecast(self, timely='current'):
geolocator = GoogleV3()
location = geolocator.geocode(self.profile.get_location())
api_key = Config.open_api.dark_sky.TOKEN
lat = location.latitude
lon = location.longitude
dark_sky = forecastio.load_forecast(api_key, lat, lon)
if timely == 'current':
currently = dark_sky.currently()
self.__forecast(currently, timely, location.address)
elif timely == 'daily':
hourly = dark_sky.hourly()
self.__forecast(hourly, timely, location.address)
elif timely == 'weekly':
daily = dark_sky.daily()
self.__forecast(daily, timely, location.address)
示例4: get_weather
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def get_weather(self, latitude, longitude):
"""
Returns the weather for a given latitude and longitude.
"""
import forecastio
# @TODO: Find some way to suppress the warnings generated by this.
forecast = forecastio.load_forecast(self.forecastio_api_key, latitude, longitude)
return forecast.hourly().summary
示例5: at_repeat
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def at_repeat(self):
"called every self.interval seconds."
if not self.obj.db.location:
return
loc = self.obj.db.location.split(',')
if not self.db.API_key:
self.db.API_Key = 'e07c570e1f5f85a42dacce70bc6c63ce'
# if location contains lat, lng
if len(loc)==2:
# Get Weather from Forecast.io
forecast = forecastio.load_forecast(self.db.API_Key, loc[0], loc[1])
# Extract current weather summary
self.obj.db.cweather = forecast.currently().summary
示例6: at_start
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def at_start(self):
if not self.db.API_key:
self.db.API_Key = 'e07c570e1f5f85a42dacce70bc6c63ce'
if not self.db.fogmessage:
self.db.fogmessage = ['A mist hangs over everything','The fog turns everything into murky shadows','You worry about your footing in the dense fog']
self.db.clearmessage = ['The bright sky feels light and carefree','The energy of the earth refreshes you','A clear day','Sunlight warms your face','The trees are bright and green','You hear the laughter of undergrads','You wish you had a frisbee']
self.db.cloudmessage = ['Clouds sweep across the sky.','A faint breeze is felt','A cloud in the distance reminds you of something','Tree branches creak and sway in the wind','A chill comes over you','You see a mountain in the distance']
self.db.rainmessage = ['The rain falls heavily on the ground','The dark clouds are pregnant with rain','The ground is slick, be careful','Rain, rain, go away, come again some other day']
self.db.snowmessage = ['White snow blankets the world','The cold bites at your face']
self.db.raremessage = ['You feel a pang of nostalgia','A faint smell reminds you of your mother','The air tastes like metal','You feel hopeless and lost','The meaninglessness of existence overcomes you','There\'s some trash on the ground','There doesn\'t seem to be anyone around','You notice the hum of electricity. Has it always been there?','The wounds of your childhood ache']
# search for veggies in room
veggies_in_room = [obj for obj in self.obj.contents_get() if utils.inherits_from(obj, objects.Vegetable)]
# if not veggies in room
if not veggies_in_room:
prototype = random.choice(self.db.available_veggies)
# use the spawner to create a new Vegetable from the spawner dictionary
veggie = spawn(objects.VEGETABLE_PROTOTYPES[prototype], prototype_parents=objects.VEGETABLE_PROTOTYPES)[0]
veggie.location = self.obj
veggiestring = ("A %s ripens" % veggie)
self.obj.msg_contents(veggiestring)
self.obj.msg_contents("DATA,obj_add," + veggie + veggie.dbref)
# if weather not set for room
if not self.db.cweather and self.db.location:
loc = self.obj.db.location.split(',')
# if location contains lat, lng
if len(loc)==2:
# Get Weather from Forecast.io
forecast = forecastio.load_forecast(self.db.API_Key, loc[0], loc[1])
# Extract and store current weather summary
self.obj.cweather = forecast.currently().summary
示例7: read
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def read():
if invalidConfig:
if forecast_debug_enabled:
forecast_logger.debug('Invalid config, aborting read')
return []
debug_message = 'Reading Temp for (lat: %s, long: %s) from %s' % (forecast_latitude, forecast_longitude, plugin_name)
if not forecast_read_enabled:
debug_message += ' [SIMULATED]'
forecast_logger.debug(debug_message)
if forecast_read_enabled:
try:
forecast = forecastio.load_forecast(forecast_api_key, forecast_latitude, forecast_longitude)
except Exception, e:
forecast_logger.error("DarkSky API error - aborting read:\n%s", e)
return []
temp = round(forecast.currently().temperature, 1)
else:
temp = round(random.uniform(12.0, 23.0), 1)
if forecast_debug_enabled:
forecast_logger.debug('%s: %s (%s)', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'), forecast_zone, temp)
return [Temperature(forecast_zone, temp)]
# if called directly then this is what will execute
示例8: fetch_weather
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def fetch_weather(latitude, longitude, date):
apikey = 'd5e9ae1a96b8e4a1509ceba9e8ebd92d'
formatted_date = datetime.datetime(*date)
if len(longitude) == 0:
weather_list = ['', 'null']
return(weather_list)
else:
try:
forecast = forecastio.load_forecast(apikey, latitude, longitude, time=formatted_date)
weather = forecast.currently()
weather_list = [('{}°C'.format(weather.temperature)), weather.icon]
return(weather_list)
except:
weather_list = ['', 'null']
return(weather_list)
示例9: get_weather
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def get_weather(self, latitude, longitude):
"""
Returns the weather for a given latitude and longitude.
"""
# @TODO: Find some way to suppress the warnings generated by this.
forecast = forecastio.load_forecast(self.forecastio_api_key, latitude, longitude)
return forecast.hourly().summary
示例10: _update
# 需要导入模块: import forecastio [as 别名]
# 或者: from forecastio import load_forecast [as 别名]
def _update(self):
"""Get the latest data from Dark Sky."""
import forecastio
try:
self.data = forecastio.load_forecast(
self._api_key, self.latitude, self.longitude, units=self.units)
except (ConnectError, HTTPError, Timeout, ValueError) as error:
raise ValueError("Unable to init Dark Sky. %s", error)
self.unit_system = self.data.json['flags']['units']