本文整理汇总了Python中pywapi.get_weather_from_weather_com函数的典型用法代码示例。如果您正苦于以下问题:Python get_weather_from_weather_com函数的具体用法?Python get_weather_from_weather_com怎么用?Python get_weather_from_weather_com使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_weather_from_weather_com函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getWeather
def getWeather():
global cityID_, zip_, city_, temperature_, conditions_
if city_ != "":
city = pywapi.get_location_ids(city_)
cityID = list(city.keys())
tmp = list(city.values())
city_ = tmp[0]
cityID_ = cityID
result = pywapi.get_weather_from_weather_com(cityID[0])
conditions_ = str(result['current_conditions']['text'])
temperature_ = float(result['current_conditions']['temperature']) * 1.8 + 32
else:
newCity = ""
zip = pywapi.get_location_ids(zip_)
cityName = list(zip.values())
for i in cityName[0]:
if not i.isdigit() and i != '(' and i != ')':
newCity += i
city_ = newCity
cityList = pywapi.get_location_ids(newCity)
cityID = list(cityList.keys())
cityID_ = cityID
result = pywapi.get_weather_from_weather_com(cityID[0])
conditions_ = str(result['current_conditions']['text'])
temperature_ = float(result['current_conditions']['temperature']) * 1.8 + 32
示例2: get_weather
def get_weather(self, location_id):
"""
can enter location ID from weather.com
or 5 digit zip code
"""
if len(location_id) < 5:
results = "No match for location entered could be found."
elif len(location_id) == 5:
weather_com_result = pywapi.get_weather_from_weather_com(location_id, units="imperial")
results = (
"According to Weather.com: It is "
+ string.lower(weather_com_result["current_conditions"]["text"])
+ " and "
+ weather_com_result["current_conditions"]["temperature"]
+ "F now in zip code %s .\n\n" % location_id
)
else:
weather_com_result = pywapi.get_weather_from_weather_com(location_id, units="imperial")
results = (
"According Weather.com: It is "
+ string.lower(weather_com_result["current_conditions"]["text"])
+ " and "
+ weather_com_result["current_conditions"]["temperature"]
+ "F now in %s.\n\n" % self.given_location
)
return results
示例3: getData
def getData():
cities = pywapi.get_cities_from_google('de') # or (country = 'fr', hl = 'de')
locidparis = pywapi.get_loc_id_from_weather_com("Paris")
locidbs = pywapi.get_loc_id_from_weather_com("Braunschweig")
locidlondon = pywapi.get_loc_id_from_weather_com("London")
Bs = pywapi.get_weather_from_weather_com("GMXX0013")
Paris = pywapi.get_weather_from_weather_com("FRXX0076")
London = pywapi.get_weather_from_weather_com("UKXX0085")
datetime = time.strftime("Date: %d-%B-%Y Time: %H:%M:%S")
tempBs = str(Bs['current_conditions']['temperature'])
tempLondon = str(London['current_conditions']['temperature'])
tempParis = str(Paris['current_conditions']['temperature'])
## pp.pprint(datetime)
## pp.pprint("Aktuelle Temperatur in Braunschweig: " + tempBs +" Grad")
## pp.pprint("Aktuelle Temperatur in London: " + tempLondon +" Grad")
## pp.pprint("Aktuelle Temperatur in Paris: " + tempParis +" Grad")
werte = [('Braunschweig', tempBs, str(datetime)),
('London', tempLondon, str(datetime)),
('Paris', tempParis, str(datetime))]
cursor.executemany("INSERT INTO temperatures VALUES (?,?,?)", werte)
connection.commit()
示例4: weersomstandigheden
def weersomstandigheden():
"""Haalt huidige weersomstandigheden van weather.com."""
global weather_com_result_hvh, weather_com_result_r, weather_com_result_d
weather_com_result_hvh = pywapi.get_weather_from_weather_com('NLXX0025', units='metric')
weather_com_result_r = pywapi.get_weather_from_weather_com('NLXX0015', units='metric')
weather_com_result_d = pywapi.get_weather_from_weather_com('NLXX0006', units='metric')
root.after(60000, weersomstandigheden)
示例5: weersomstandigheden_pred
def weersomstandigheden_pred():
"""Haalt huidige weersomstandigheden van weather.com."""
global weather_com_pred_hvh, weather_com_pred_r, weather_com_pred_d, dag1, dag2, dag3, dag4
try:
weather_com_pred_hvh = pywapi.get_weather_from_weather_com( 'NLXX0025', units = 'metric' )
weather_com_pred_r = pywapi.get_weather_from_weather_com( 'NLXX0015', units = 'metric' )
weather_com_pred_d = pywapi.get_weather_from_weather_com( 'NLXX0006', units = 'metric' )
dag1 = weather_com_pred_hvh['forecasts'][1]['date']
dag2 = weather_com_pred_hvh['forecasts'][2]['date']
dag3 = weather_com_pred_hvh['forecasts'][3]['date']
dag4 = weather_com_pred_hvh['forecasts'][4]['date']
except:
print("Kan weersvoorspelling niet ophalen.")
示例6: handle
def handle(text, mic, profile):
weather_com_result = pywapi.get_weather_from_weather_com('SZXX0728')
weather_status = weather_com_result['current_conditions']['text']
weather_felttemp = weather_com_result['current_conditions']['feels_like']
weather = "The weather conditions are "+weather_status+" with a felt temperature of "+ weather_felttemp+ " degrees Celsius. "
if ("clothes" in text.lower()) or ("wear" in text.lower()):
chance_rain = rain(weather_com_result['forecasts'])
felttemp_int = int(weather_felttemp)
weather_suggestion = temperatureSuggestion(felttemp_int)
weather_suggestion += chance_rain
mic.say(weather_suggestion)
elif ("hot" in text.lower()) or ("temperature" in text.lower()) or ("cold" in text.lower()):
mic.say("There's currently a felt temperature of "+weather_felttemp+" degrees Celsius.")
elif "rain" in text.lower():
rainprop = rain(weather_com_result['forecasts'])
mic.say(rainprop)
else :
mic.say(weather)
示例7: on_status
def on_status(self, status):
print status.text
reply = status.user.screen_name
print status.user.screen_name
weather_com_result = pywapi.get_weather_from_weather_com('zipcodehere', units ='imperial') #can be imperial or metric
now = time.strftime("[%I:%M %p] ")
api.update_status(now + "@" + reply + " It is currently " + weather_com_result['current_conditions']['text'].lower() + " and " + weather_com_result['current_conditions']['temperature'] + "F.", in_reply_to_status_id = status.id)
示例8: get_trip_info
def get_trip_info(args):
info = vars(args)
#TODO: add something for when forecast cannot be fetched.
forecasts = pywapi.get_weather_from_weather_com(info['zip_code'],
units='imperial')['forecasts']
if len(forecasts) < info['days']+1:
print('warning: forecast unavailable for part of trip duration')
info.update(minimum_temperature=min(float(daily['low'])
for daily in forecasts[1:info['days']+1]))
info.update(maximum_temperature=max(float(daily['high'])
for daily in forecasts[1:info['days']+1]))
prob_no_rain = 1
prob_no_snow = 1
#When evaluating the chance of precipitation, include the day you're
#leaving/arriving (excluded above when looking at temperatures).
for daily in forecasts[0:info['days']+1]:
#Could argue that the first *day* shouldn't factor in the daytime
#forecast. Simpler this way, though.
prob_no_precip = (1-0.01*float(daily['day']['chance_precip'])*
1-0.01*float(daily['night']['chance_precip']))
if float(daily['high']) >= WATER_FREEZING_POINT:
prob_no_rain *= prob_no_precip
if float(daily['low']) <= WATER_FREEZING_POINT:
prob_no_snow *= prob_no_precip
info.update(rain=1-prob_no_rain >= info['rain_threshold'])
info.update(snow=1-prob_no_snow >= info['snow_threshold'])
return info
示例9: __init__
def __init__(self, setCity, setLocation, setUnits = "metric"):
self.location = setLocation
self.units = setUnits
self.city = setCity
self.weatherData = pywapi.get_weather_from_weather_com(self.location, units = self.units )
self.astrology = Astral()
self.sunLocation = self.astrology[self.city]
示例10: 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()
示例11: weather
def weather(self, order):
words = order.split(" ")
try:
city_index = words.index("in") + 1
except ValueError:
self.add_anger()
print "Wrong syntax"
return("No!")
if words[city_index] == "city":
city_index+=1
if words[-1] == "please":
city_arr = words[city_index:-1]
self.add_please()
else:
city_arr = words[city_index:]
city = " ".join(city_arr)
loc_id = pywapi.get_location_ids(city)
city_id = self.get_city_id(loc_id)
try:
self.add_please()
all_info = pywapi.get_weather_from_weather_com( city_id , units = 'metric' )
weather = all_info['current_conditions']['temperature']
text = all_info['current_conditions']['text']
weather_respone = ('It is ' + text + ', Temperature: ' + weather + ' celsius degrees in ' + city)
return(weather_respone)
except:
e = sys.exc_info()[0]
print "Error: %s" % e
print "Weather occurs some problems"
return("NO!")
示例12: forecast
def forecast(bot, event, *args):
if args:
place = ' '.join(args)
lookup = pywapi.get_location_ids(place)
for i in lookup:
location_id = i
else:
location_id = 'USVA0140'
yield from bot.coro_send_message(event.conv, _("No location given; defaulting to Chantilly, VA"))
weather_com_result = pywapi.get_weather_from_weather_com(
location_id, units='imperial')
place = weather_com_result['location']['name']
high = weather_com_result['forecasts'][1]['high']
low = weather_com_result['forecasts'][1]['low']
day = weather_com_result['forecasts'][1]['day']['text']
if day == '':
day = 'N/A'
night = weather_com_result['forecasts'][1]['night']['text']
if night == '':
night = 'N/A'
date = weather_com_result['forecasts'][1]['date']
url = links.shorten(
'http://www.weather.com/weather/today/l/' + location_id)
msg = _("<b>Forecast for {} on {}:</b><br>Conditions: Day - {}; Night - {}<br>High: {}<br>Low: {}<br>For more information visit {}").format(
place, date, day, night, high, low, url)
yield from bot.coro_send_message(event.conv, msg)
示例13: weather
def weather(bot, event, *args):
'''Gets weather from weather.com. Defaults to Chantilly, VA if no location given. Format is /bot weather <city>,<state/country>'''
try:
if args:
place = ' '.join(args)
lookup = pywapi.get_location_ids(place)
for i in lookup:
location_id = i
else:
location_id = 'USVA0140'
yield from bot.coro_send_message(event.conv, _("No location given; defaulting to Chantilly, VA"))
weather_com_result = pywapi.get_weather_from_weather_com(
location_id, units='imperial')
condition = weather_com_result['current_conditions']['text'].lower()
temp = weather_com_result['current_conditions']['temperature']
feelslike = weather_com_result['current_conditions']['feels_like']
place = weather_com_result['location']['name']
url = links.shorten(
'http://www.weather.com/weather/today/l/' + location_id)
msg = _('<b>Today in {}:</b><br>Temp: {}°F (Feels like: {}°F)<br>Conditions: {}<br>For more information visit {}').format(
place, temp, feelslike, condition, url)
yield from bot.coro_send_message(event.conv, msg)
except BaseException as e:
msg = _('{} -- {}').format(str(e), event.text)
yield from bot.coro_send_message(CONTROL, msg)
示例14: speakWeather
def speakWeather( config, string ):
location_code = config.get( "weather", "weather_location_code" )
weather_com_result = pywapi.get_weather_from_weather_com( str(location_code ))
print weather_com_result
print string
lookupString = ''
### TODAY
if ( re.compile( "today", re.IGNORECASE ).findall( string ,1 )):
todayData = weather_com_result['forecasts'][0]
if ( todayData['day']['text'] != 'N/A' ):
if ( int( todayData['day']['chance_precip'] ) > 40 ):
lookupString = "Today will be " + str( todayData['day']['text'] ) + " with a chance of showers and a high of " + str( todayData['high'] ) + "degrees"
else:
lookupString = "Today will be " + str( todayData['day']['text'] ) + " with a high of " + str( todayData['high'] ) + "degrees"
else:
if ( int(todayData['night']['chance_precip'] ) > 40 ):
lookupString = "Tonight will be " + str( todayData['night']['text'] ) + " with a chance of showers"
else:
lookupString = "Tonight will be " + str( todayData['night']['text'] )
### TONIGHT
elif ( re.compile( "tonight", re.IGNORECASE).findall( string ,1 )):
todayData = weather_com_result['forecasts'][0]
if ( int(todayData['night']['chance_precip'] ) > 40 ):
lookupString = "Tonight will be " + str( todayData['night']['text'] ) + " with a chance of showers"
else:
lookupString = "Tonight will be " + str( todayData['night']['text'] )
### Tomorrow Night
elif ( re.compile( "tomorrow night", re.IGNORECASE).findall( string ,1 )):
todayData = weather_com_result['forecasts'][1]
if ( int(todayData['night']['chance_precip'] ) > 40 ):
lookupString = "Tomorrow night will be " + str( todayData['night']['text'] ) + " with a chance of showers"
else:
lookupString = "Tomorrow night will be " + str( todayData['night']['text'] )
### TODAY
elif ( re.compile( "tomorrow", re.IGNORECASE ).findall( string ,1 )):
todayData = weather_com_result['forecasts'][1]
if ( todayData['day']['text'] != 'N/A' ):
if (( int( todayData['day']['chance_precip'] ) > 40 ) or ( int( todayData['night']['chance_precip'] ) > 40 )):
lookupString = "Tomorrow will be " + str( todayData['day']['text'] ) + " with a chance of showers and a high of " + str( todayData['high'] ) + " degrees"
else:
lookupString = "Tomorrow will be " + str( todayData['day']['text'] ) + " with a high of " + str( todayData['high'] ) + "degrees"
else:
lookupString = "It is currently " + str(weather_com_result['current_conditions']['text']) + " and " + weather_com_result['current_conditions']['temperature'] + "degrees.\n\n"
print lookupString
## Work our magic
if ( lookupString != '' ):
GoogleSpeech.tts( lookupString )
else:
GoogleSpeech.tts( "Sorry, Weather information un-available at this time, please try again later" )
示例15: 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