本文整理汇总了Python中pywapi.get_weather_from_yahoo函数的典型用法代码示例。如果您正苦于以下问题:Python get_weather_from_yahoo函数的具体用法?Python get_weather_from_yahoo怎么用?Python get_weather_from_yahoo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_weather_from_yahoo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
old_temp = 0
old_humidity = 0
old_dewpoint = 0
while (True):
try:
yahooweather_result = pywapi.get_weather_from_yahoo(readID)
if yahooweather_result != "":
condizioni = yahooweather_result['condition']['text']
temperatura = float(yahooweather_result['condition']['temp'])
umidita = float(yahooweather_result['atmosphere']['humidity'])
dew = calc_dewpoint(temperatura, umidita)
if temperatura != old_temp:
if (readTempUnits == 'f' or readTempUnits == 'F'):
tempF = round(celsius_to_fahrenheit(temperatura))
client.emit_event(temp, "event.environment.temperaturechanged", tempF, "F")
else:
client.emit_event(temp, "event.environment.temperaturechanged", temperatura, "C")
if umidita != old_humidity:
client.emit_event(humidity, "event.environment.humiditychanged", umidita, "%")
search_Rain = string.find(condizioni, "Rain")
search_Drizzle = string.find(condizioni, "Drizzle")
if (search_Rain >= 0) or (search_Drizzle >=0):
client.emit_event(rain,"event.device.statechanged", "255", "")
else :
client.emit_event(rain,"event.device.statechanged", "0", "")
except KeyError:
print "Error retrieving weather data!"
old_temp = temperatura
old_humidity = umidita
old_dewpoint = dew
time.sleep (readWaitTime)
示例2: GenerateWeatherConditionsText
def GenerateWeatherConditionsText(self):
zipcode = '89129'
weather = pywapi.get_weather_from_yahoo(zipcode)
condition = weather['condition']['text'].encode('UTF-8')
humidity = weather['atmosphere']['humidity'].encode('UTF-8')
temp_celsius = float(weather['condition']['temp'])
temp = str( round(self.celsius2farenheight(temp_celsius),2)).encode('UTF-8')
wind_mps = float( weather['wind']['speed'] )
wind = str( round(self.mps2mph(wind_mps),2) ).encode('UTF-8')
date_1 = weather['forecasts'][0]['date']
date_2 = weather['forecasts'][1]['date']
time_1 = time.strftime("%a, %b %d",time.strptime(date_1, "%d %b %Y")).encode('UTF-8')
time_2 = time.strftime("%a, %b %d",time.strptime(date_2, "%d %b %Y")).encode('UTF-8')
forecast_temp_low_1 = str(int(self.celsius2farenheight(float(weather['forecasts'][0]['low'])))).encode('UTF-8')
forecast_temp_high_1 = str(int(self.celsius2farenheight(float(weather['forecasts'][0]['high'])))).encode('UTF-8')
forecast_text_1 = weather['forecasts'][0]['text'].encode('UTF-8')
forecast_temp_low_2 = str(int(self.celsius2farenheight(float(weather['forecasts'][1]['low'])))).encode('UTF-8')
forecast_temp_high_2 = str(int(self.celsius2farenheight(float(weather['forecasts'][1]['high'])))).encode('UTF-8')
forecast_text_2 = weather['forecasts'][1]['text'].encode('UTF-8')
text = '{pause=5}{typesetOff}{fastest}{amber}{5x5}{moverightin}{moverightout}today: {7x6}{green}' + condition.encode('UTF-8') +'{nl}'
text = text + '{5x5}{amber}{moveleftin}{moveleftout}Temp: {red}{7x6}' + temp + ' degrees{nl}'
text = text + '{5x5}{amber}{moverightin}{moverightout}Humidity: {green}{7x6}' + humidity + '%{nl}'
text = text + '{5x5}{amber}{moveleftin}{moveleftout}Wind: {red}{7x6}' + wind + 'mph{nl}'
text = text + '{newframe}{fastest}{amber}{7x6}{moveupin}{movedownout}Forecast:{nl}'
text = text + '{green}' + time_1 + '{nl}'
text = text + '{red}Low:' + forecast_temp_low_1 + ' High: ' +forecast_temp_high_1 + '{nl}'
text = text + '{amber}' + forecast_text_1 + '{nl}'
text = text + '{newframe}{fastest}{amber}{7x6}{movedownin}{moveupout}Forecast:{nl}'
text = text + '{green}' + time_2 + '{nl}'
text = text + '{red}Low:' + forecast_temp_low_2 + ' High: ' +forecast_temp_high_2 + '{nl}'
text = text + '{amber}' + forecast_text_2 + '{nl}'
return text
示例3: Weather
def Weather(self):
for i in self.trying:
i.Destroy()
self.trying = []
sizer = wx.GridBagSizer()
temp_actuel=T.time()
weather_com_result = pywapi.get_weather_from_weather_com('10001')
yahoo_result = pywapi.get_weather_from_yahoo('10001')
noaa_result = pywapi.get_weather_from_noaa('KJFK')
weather1 = self.trying.append(wx.StaticText(self.BoxStock,-1,str("Yahoo says: It is " + string.lower(yahoo_result['condition']['text']) + " and " +
yahoo_result['condition']['temp'] + " C now "),pos=(50,50)))
# labelStock = wx.StaticText(self.BoxStock,-1,label=weather1,pos=(30,30))
#self.text.SetLabel(str(labelStock))
#weather2 = "Weather.com says: It is " + string.lower(weather_com_result['current_conditions']['text']) + " and " + weather_com_result['current_conditions']['temperature'] + " C now "
#labelStock = wx.StaticText(self.BoxStock,label=weather2,pos=(30,80))
#self.text.SetLabel(str(labelStock))
wx.CallLater(10000,self.Weather)
message=string.lower(yahoo_result['condition']['text'])
if message=="fair":
#from PIL import Image
#bidule = Image.open("image/nuage-noir-avec-de-la-pluie.jpg")
#bidule.show()
app= Application(redirect=True)
app.MainLoop()
示例4: get_wind
def get_wind(zip, units):
weather = pywapi.get_weather_from_yahoo(zip)
wind = 'No wind'
if weather['wind']['speed'] > 1:
wind = 'Wind %dmph from %s' % (float(weather['wind']['speed']), \
get_wind_direction(weather['wind']['direction']))
return wind
示例5: __init__
def __init__(self):
self.result = pywapi.get_weather_from_yahoo('SPXX0050', 'metric')
icon = self.__code_to_something(self.result['condition']['code'])
if icon:
self.result['condition']['icon'] = icon
if 'link' in self.result:
self.result['condition']['link'] = self.result['link']
示例6: getWeatherMemoized
def getWeatherMemoized():
global lastweather, wTemp, wIcon
#update hourly
if (time.time() - lastweather > 60 * 60):
lastweather = time.time()
wres = pywapi.get_weather_from_yahoo('10001')
wTemp = (wres['condition']['temp'] + u"°C"
#+ wres['condition']['text']
)
#print wres
cond = wres['condition']['text']
if cond == u"Sunny":
wIcon = u"⛭"
elif cond == u"Mostly Sunny":
wIcon = u"⛯"
elif cond == u"Fair":
wIcon = u"⚙"
elif cond == u"Partly Cloudy":
wIcon = u"⛅"
elif cond == u"Cloudy":
wIcon = u"☁"
elif cond == u"Raining":
wIcon = u"☔" #☂
elif cond == u"Snowing":
wIcon = u"⛄"
else:
wIcon = u"☭"
示例7: show_temp
def show_temp():
yahoo_weather = pywapi.get_weather_from_yahoo('78728', 'imperial')
for ch in yahoo_weather['condition']['temp']:
display.display_char_fade(ch, color_tools.random_rgb(), 300)
display.display_char_fade(chr(0xb0), color_tools.random_rgb(), 300)
display.display_char_fade('f', color_tools.random_rgb(), 300)
time.sleep(0.4)
示例8: get
def get(self):
auth = tweepy.OAuthHandler('wJynZvsXCJDbxFavJZMuvQ','Ua9HSGqJntKpBMfTYuldjuplo3XUlC3QovTn7EOQ')
auth.set_access_token('400026591-XCtPsJABBP5MGF13Q4xFVXZurRcVtCcJ0VaU9Dr5', '635W0s9PIVYxlVktp0hWiNkBfNS4ntuW7c2thGsp8')
api = tweepy.API(auth)
location = 'Mataram'
f = urllib2.urlopen('http://api.wunderground.com/api/da229b2203c824d3/geolookup/conditions/q/IA/' + location +'.json')
json_string = f.read()
parsed_json = json.loads(json_string)
resYahoo = pywapi.get_weather_from_yahoo('IDXX0032', 'metric')
time = datetime.datetime.utcnow() + datetime.timedelta(hours = 8)
location = parsed_json['location']['city']
current = parsed_json['current_observation']['weather']
temp_c = parsed_json['current_observation']['temp_c']
humidity = parsed_json['current_observation']['relative_humidity']
visibility = parsed_json['current_observation']['visibility_km']
f.close()
sunrise = resYahoo['astronomy']['sunrise']
sunset = resYahoo['astronomy']['sunset']
wind = resYahoo['wind']['speed'] + ' km'
winddir = resYahoo['wind']['direction']
update = time.strftime("%Y-%m-%d, %H:%M") + ' WITA : ' + location + ' ' + current + ' ' + str(temp_c) +' C' + ', Humidity: ' + humidity +', ' + ' Visibility: ' + visibility + ' km'
update = update + ', Wind: ' + wind + ', Sunrise: ' + sunrise + ', Sunset: ' + sunset
self.response.out.write(update)
api.update_status(update)
示例9: run
def run(self, wcd, wci):
"""
Displaying expected temperature
"""
# Get current forecast
if self.weather_service == "yahoo":
current_weather_forecast = pywapi.get_weather_from_yahoo(self.location_id)
elif self.weather_service == "weather_dot_com":
current_weather_forecast = pywapi.get_weather_from_weather_com(self.location_id)
else:
print("Warning: No valid weather_forecast found!")
return
outdoor_temp = current_weather_forecast["current_conditions"]["temperature"]
if self.temp_sensor_registered:
try:
indoor_temp = str(int(round(am2302_ths.get_temperature(4))))
wcd.showText(outdoor_temp + "*", count=1, fps=8)
wcd.showText(indoor_temp + "*", count=1, fg_color=wcc.GREEN, fps=8)
wcd.showText(outdoor_temp + "*", count=1, fps=8)
wcd.showText(indoor_temp + "*", count=1, fg_color=wcc.GREEN, fps=8)
except:
print(" Failed to read temperature sensor!")
wcd.showText(outdoor_temp + "* " + outdoor_temp + "* " + outdoor_temp + "*", count=1, fps=8)
else:
wcd.showText(outdoor_temp + "* " + outdoor_temp + "* " + outdoor_temp + "*", count=1, fps=8)
time.sleep(1)
示例10: weather
def weather(args):
try:
result = pywapi.get_weather_from_yahoo(
str(args[0]).replace("_", " "), "imperial")
current_conditions = result["condition"][
"title"] + ": " + result["condition"]["text"] + \
", " + result["condition"]["temp"]
five_day_forecast = result["forecasts"]
forecast_1 = str(five_day_forecast[0]["day"]) + ": " + str(five_day_forecast[0]["text"]) + ", " + str(
five_day_forecast[0]["high"]) + ", " + str(five_day_forecast[0]["low"]) + " | "
forecast_2 = str(five_day_forecast[1]["day"]) + ": " + str(five_day_forecast[1]["text"]) + ", " + str(
five_day_forecast[1]["high"]) + ", " + str(five_day_forecast[1]["low"]) + " | "
forecast_3 = str(five_day_forecast[2]["day"]) + ": " + str(five_day_forecast[2]["text"]) + ", " + str(
five_day_forecast[2]["high"]) + ", " + str(five_day_forecast[2]["low"]) + " | "
forecast_4 = str(five_day_forecast[3]["day"]) + ": " + str(five_day_forecast[3]["text"]) + ", " + str(
five_day_forecast[3]["high"]) + ", " + str(five_day_forecast[3]["low"]) + " | "
forecast_5 = str(five_day_forecast[4]["day"]) + ": " + str(five_day_forecast[4][
"text"]) + ", " + str(five_day_forecast[4]["high"]) + ", " + str(five_day_forecast[4]["low"])
forecasts = forecast_1 + forecast_2 + \
forecast_3 + forecast_4 + forecast_5
return current_conditions # + " | Forecasts: " + forecasts
except:
return "Zip codes only, at the moment, plz."
示例11: run
def run(self, wcd, wci):
"""
Displaying expected temperature
"""
# Get current forecast
if self.weather_service == 'yahoo':
current_weather_forecast = pywapi.get_weather_from_yahoo(self.location_id)
elif self.weather_service == 'weather_dot_com':
current_weather_forecast = pywapi.get_weather_from_weather_com(self.location_id)
else:
print('Warning: No valid weather_forecast found!')
return
outdoor_temp = current_weather_forecast['current_conditions']['temperature']
if self.temp_sensor_registered:
try:
indoor_temp = str(int(round(am2302_ths.get_temperature(self.pin_temp_sensor))))
wcd.showText(outdoor_temp + '*', count=1, fps=8)
wcd.showText(indoor_temp + '*', count=1, fg_color=wcc.GREEN, fps=8)
wcd.showText(outdoor_temp + '*', count=1, fps=8)
wcd.showText(indoor_temp + '*', count=1, fg_color=wcc.GREEN, fps=8)
except:
print(' Failed to read temperature sensor!')
wcd.showText(outdoor_temp + '* ' + outdoor_temp + '* ' + outdoor_temp + '*', count=1, fps=8)
else:
wcd.showText(outdoor_temp + '* ' + outdoor_temp + '* ' + outdoor_temp + '*', count=1, fps=8)
if wci.waitForExit(1.0):
return
示例12: post
def post(self):
invalid = False
username = self.request.cookies.get("username")
users = User.query(User.username == username).fetch()
user = users[0]
zip_code = str(self.request.get("zip"))
user.zipcode = zip_code
user.put()
if self.postalValidate(zip_code):
yahoo_result = pywapi.get_weather_from_yahoo(zip_code)
currentTemp = ((float(yahoo_result['condition']['temp'])*1.8) + 32)
conditions = str(yahoo_result['condition']['text'])
location = str(yahoo_result['condition']['title'])
location = location.replace("Conditions for ", "")
template_values = {
'currentTemp': currentTemp,
'conditions': conditions,
'location': location,
'zip_code': zip_code,
'user': user,
}
template = JINJA_ENVIRONMENT.get_template('weather.html')
self.response.write(template.render(template_values))
else:
invalid = True
template_values = {
'invalid': invalid,
'zip_code': zip_code
}
template = JINJA_ENVIRONMENT.get_template('weather.html')
self.response.write(template.render(template_values))
示例13: weather_info
def weather_info(self):
details = pywapi.get_weather_from_yahoo(CITY_ID)
if 'error' in details:
logging.critical('City not found. Shutting down weather thread.')
sys.exit()
weather_data = {'{0}' : details['location']['city'],
'{1}' : details['condition']['date'],
'{2}' : details['condition']['code'],
'{3}' : details['condition']['temp'],
'{4}' : details['condition']['text'],
'{5}' : details['astronomy']['sunrise'],
'{6}' : details['astronomy']['sunset'],
'{7}' : details['atmosphere']['humidity'],
'{8}' : details['atmosphere']['pressure'],
'{9}' : details['forecasts'][0]['day'],
'{10}' : details['forecasts'][0]['text'],
'{11}' : details['forecasts'][0]['code'],
'{12}' : details['forecasts'][0]['low'],
'{13}' : details['forecasts'][0]['high'],
'{14}' : details['forecasts'][1]['day'],
'{15}' : details['forecasts'][1]['text'],
'{16}' : details['forecasts'][1]['code'],
'{17}' : details['forecasts'][1]['low'],
'{18}' : details['forecasts'][1]['high']}
outstring = insert_data(self.format_string, weather_data)
with open(os.path.expanduser('~/.local/share/skutter/weather'), 'w') as g:
g.write(outstring)
示例14: get_weather_info
def get_weather_info(location):
id = get_location_id(location)
result = pywapi.get_weather_from_yahoo(id, 'metric')
if not result:
return {}
output = dict(result)
return output
示例15: weather
def weather(request):
locations = ["94041", "90008", "97202", "94110", "10024",
"02111", "60605", "23454", "32804", "75204",
"98112", ]
forecasts = []
for location in random.sample(locations, 4):
forecasts.append(pywapi.get_weather_from_yahoo(location))
return render_to_response("petclinic/weather/weather_basic.html", { 'forecasts': forecasts })