• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pywapi.get_weather_from_google函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pywapi.get_weather_from_google函数的典型用法代码示例。如果您正苦于以下问题:Python get_weather_from_google函数的具体用法?Python get_weather_from_google怎么用?Python get_weather_from_google使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_weather_from_google函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: getWeather

def getWeather(zipcode, pathPrefix = ''):
    weather = pywapi.get_weather_from_google('02139')
    result = {}
    result['nowtime'] = weather['forecast_information']['current_date_time']
    result['nowicon'] = pathPrefix + getIcon(weather['current_conditions']['condition'])
    result['nowtemp'] = weather['current_conditions']['temp_f'] + '°'
    result['nowtitle'] = weather['current_conditions']['condition'] 
    result['nowlocation'] = weather['forecast_information']['city']
    
    result['todayicon'] = pathPrefix + getIcon(weather['forecasts'][0]['condition']) 
    result['todaytitle'] = weather['forecasts'][0]['condition']
    result['todaytemphigh'] = weather['forecasts'][0]['high']  + '°'
    result['todaytemplow'] = weather['forecasts'][0]['low'] + '°'

    result['tomorrowicon'] = pathPrefix + getIcon(weather['forecasts'][1]['condition'])
    result['tomorrowtitle'] = weather['forecasts'][1]['condition']
    result['tomorrowtemphigh'] = weather['forecasts'][1]['high']  + '°'
    result['tomorrowtemplow'] = weather['forecasts'][1]['low']  + '°'

    result['dayaftericon'] = pathPrefix + getIcon(weather['forecasts'][2]['condition'])
    result['dayaftertitle'] = weather['forecasts'][2]['condition']
    result['dayaftertemphigh'] = weather['forecasts'][2]['high']  + '°'
    result['dayaftertemplow'] = weather['forecasts'][2]['low']  + '°'
    
    return result
开发者ID:dormbase,项目名称:dashboard,代码行数:25,代码来源:weather.py


示例2: weather

    def weather(self, params=None, **kwargs):
        """Display current weather report (ex: .w [set] [<location>])"""
        if params:
            location = params
            if location.startswith("set "):
                location = location[4:]
                utils.write_file(self.name, self.irc.source, location)
                self.irc.reply("Location information saved")
        else:
            location = utils.read_file(self.name, self.irc.source)
            if not location:
                self.irc.reply(self.weather.__doc__)
                return

        try:
            w = pywapi.get_weather_from_google(location)
        except Exception:
            self.irc.reply("Unable to fetch weather data")
            return

        if w["current_conditions"]:
            city = w["forecast_information"]["city"]
            temp_f = w["current_conditions"]["temp_f"]
            temp_c = w["current_conditions"]["temp_c"]
            humidity = w["current_conditions"]["humidity"]
            wind = w["current_conditions"]["wind_condition"]
            condition = w["current_conditions"]["condition"]

            result = "%s: %sF/%sC   %s   %s   %s" % (city, temp_f, temp_c,
                    humidity, wind, condition)
            self.irc.reply(result)
        else:
            self.irc.reply("Location not found: '%s'" % location)
开发者ID:SandyWalsh,项目名称:pyhole,代码行数:33,代码来源:weather.py


示例3: handle_saa

def handle_saa(bot, channel, user, message):

    city = message
    if not city:
        city = "Rovaniemi"

    result = pywapi.get_weather_from_google(city, 'FI')
    #{'current_conditions': {}, 'forecast_information': {}, 'forecasts': []

    if not result['current_conditions']:
        answer = "Weather condition for '%s' was not found.  " % city
        bot.sendMessage(channel, user, answer.encode('utf-8'))
        return

    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(result)

    celsius = " "+u'\u00B0'+"C"
    condition = result['current_conditions']['condition'].lower()
    humidity = result['current_conditions']['humidity'].lower()
    temp = result['current_conditions']['temp_c'].lower()+celsius
    wind = result['current_conditions']['wind_condition'].lower()

    city = u'\u0002'+city[0].capitalize() + city[1:]+u'\u000F'
    current = "%s %s, %s, %s, %s" % (city, temp, condition,humidity, wind)
    forecast = "("
    forecasts = result['forecasts']
    for day in forecasts:
        forecast += day['day_of_week'] + " " + day['low'] + "-"+day['high'] +celsius+ ", "
    forecast = forecast[:len(forecast)-2]+")"
    answer = current + " " + forecast
    bot.sendMessage(channel, user, answer.encode('utf-8'))
开发者ID:makinen,项目名称:roibot,代码行数:32,代码来源:saa.py


示例4: weather

    def weather(self, params=None, **kwargs):
        """Display current weather report (ex: .w <location>)"""
        if params:
            try:
                w = pywapi.get_weather_from_google(params)
            except Exception:
                self.irc.reply("Unable to fetch weather data")
                return

            if w["current_conditions"]:
                city = w["forecast_information"]["city"]
                temp_f = w["current_conditions"]["temp_f"]
                temp_c = w["current_conditions"]["temp_c"]
                humidity = w["current_conditions"]["humidity"]
                wind = w["current_conditions"]["wind_condition"]
                condition = w["current_conditions"]["condition"]

                result = "%s: %sF/%sC   %s   %s   %s" % (city, temp_f, temp_c,
                                                         humidity, wind,
                                                         condition)
                self.irc.reply(result)
            else:
                self.irc.reply("Location not found: '%s'" % params)
        else:
            self.irc.reply(self.weather.__doc__)
开发者ID:comstud,项目名称:pyhole,代码行数:25,代码来源:weather.py


示例5: get_weather

def get_weather():
    """Return the weather temperature and conditions for the day."""
    geodata = urllib2.urlopen("http://j.maxmind.com/app/geoip.js").read()
    country_result = re.split("country_name\(\) \{ return \'", geodata)
    country_result = re.split("'; }", country_result[1])
    city_result = re.split("city\(\)         \{ return \'", geodata)
    city_result = re.split("'; }", city_result[1])
    country = country_result[0]
    city = city_result[0]
    
    weather = pywapi.get_weather_from_google(city, country)
    
    if not weather['current_conditions']:
        print 'ERROR: Get weather failed.\n'
        return ''
    
    current_condition = string.lower(weather['current_conditions']['condition'])
    current_temp = weather['current_conditions']['temp_c']
    high_temp_f = weather['forecasts'][0]['high']
    low_temp_f = weather['forecasts'][0]['low']
    
    high_temp_c = int((int(high_temp_f) - 32) / 1.8)
    low_temp_c = int((int(low_temp_f) - 32) / 1.8)
    
    return 'The weather in ' + city + ' is currently ' + current_condition + \
           ' with a temperature of ' + current_temp + ' degrees. Today there ' + \
           'will be a high of ' + str(high_temp_c) + ', and a low of ' + str(low_temp_c) + '. '
开发者ID:adammansfield,项目名称:jarvis,代码行数:27,代码来源:jarvis.py


示例6: source

def source(location):
    info = pywapi.get_weather_from_google(location)
    if not info['forecast_information']:
        return
    assert info['forecast_information']['unit_system'] == 'US'

    cur = info['current_conditions']
    start = datetime.strptime(
        info['forecast_information']['current_date_time'].rsplit(None, 1)[0],
        '%Y-%m-%d %H:%M:%S')
    yield dict(
        time_from = start,
        time_to = start + timedelta(seconds=1),
        temperature_current = float(cur['temp_c']),
        wind_direction = cur['wind_condition'].split()[1],
        wind_speed = mph(cur['wind_condition'].split()[3]),
        condition = cur['condition'],
        humidity = float(cur['humidity'].split()[1].rstrip('%')),
    )

    # let's hope they are ordered
    for day, forecast in enumerate(info['forecasts']):
        yield dict(
            # educated guess: temperature maximum reached at 12-o-clock
            time_from = start.replace(hour=12, minute=0) + timedelta(days=day),
            time_to = (start + timedelta(days=day)).replace(hour=12, minute=0),
            condition = forecast['condition'],
            temperature_min = fahrenheit(forecast['low']),
            temperature_max = fahrenheit(forecast['high']),
        )
开发者ID:kodeaffe,项目名称:weathermashup,代码行数:30,代码来源:google.py


示例7: getCurrentCondition

 def getCurrentCondition(self):
     condition = None
     weatherDetails = pywapi.get_weather_from_google(self.location)
     cc = weatherDetails.get("current_conditions", None)
     if cc:
         condition = cc.get("condition", None)
     return condition
开发者ID:silent1mezzo,项目名称:HackTO,代码行数:7,代码来源:weather.py


示例8: update_data

 def update_data(self):
     new_data = pywapi.get_weather_from_google(self.location_code)
     if new_data != self.data:
         self.data = new_data
         self.set_data()
     else:
         new_data = None
开发者ID:joeda,项目名称:qt,代码行数:7,代码来源:weather_widget.py


示例9: run

 def run(self):
     time.sleep(2)
     weather_data = pywapi.get_weather_from_google("de-76187")
     res = "temp: " + weather_data["current_conditions"]["temp_c"]
     res = QString(res)
     print "run worked"
     print res
     self.emit(SIGNAL("output(QString)"), res)
开发者ID:joeda,项目名称:qt,代码行数:8,代码来源:final.py


示例10: exec_weather

 def exec_weather(self, bow, msg_zipcode):
     """
     """
     zipcode = bow[1] if len(bow)>=2 and bow[1] else msg_zipcode
     forecast = pywapi.get_weather_from_google(zipcode)['current_conditions']
     f_tmp = forecast['temp_f']
     condition = forecast['condition']
     weather = "The weather at %s is %sf and %s" % (zipcode, f_tmp, condition)
     return weather
开发者ID:codesf,项目名称:tincan,代码行数:9,代码来源:v1.py


示例11: getWeather

 def getWeather(self, dbref, zipcode):
     google_result = pywapi.get_weather_from_google(zipcode)
     condition = str(google_result["current_conditions"]["condition"])
     temp_f = str(google_result["current_conditions"]["temp_f"])
     temp_c = str(google_result["current_conditions"]["temp_c"])
     city = str(google_result["forecast_information"]["city"])
     
     msg = "It is %(condition)s and %(temp_f)sF (%(temp_c)sC) in %(city)s" % locals()
     self.mushPemit(dbref, msg)
开发者ID:twpage,项目名称:hankscorpio,代码行数:9,代码来源:weather.py


示例12: gparser

def gparser (city):	#Gets weather from google in case station is not working
	
	try:
		result=pywapi.get_weather_from_google(city)
		
	except:
		print '\nNo data for'+ city
		result =0

	return result
开发者ID:mauriciocap,项目名称:peko,代码行数:10,代码来源:get_report.py


示例13: fetchWeatherGoogle

def fetchWeatherGoogle():
    global g_google_result
    try:
        tmp = pywapi.get_weather_from_google(CITY)
        if DEBUG:
            print "Google read: %s" % tmp
        g_google_result = tmp
    # don't ignore user Ctrl-C or out of memory
    except KeyboardInterrupt, MemoryError:
        raise
开发者ID:edesiocs,项目名称:gigamega-micro,代码行数:10,代码来源:controller.py


示例14: add_weather_info

def add_weather_info(canvas, x, y, weather_location):
    try:
        import pywapi
    except ImportError:
        return None

    try:
        weather_info = pywapi.get_weather_from_google(weather_location)
    except Exception, e:
        return None
开发者ID:shimon,项目名称:dayhacker,代码行数:10,代码来源:dayhacker.py


示例15: get_weather

def get_weather(loc_id):
    try:
        weather = pywapi.get_weather_from_google(loc_id)
    except Exception as e:
        print e
        return "error"

    if len(weather["current_conditions"]) == 0:
        return "invalid loc_id"

    return weather
开发者ID:theUberPwner,项目名称:Python-Stuff,代码行数:11,代码来源:twitter_weather.py


示例16: GetCondition

 def GetCondition(self, latlong):
     """
     Returns the current condition from google's servers.
     
     latlong     - latitude/longitude coordinates
     """
     try:
         res = pywapi.get_weather_from_google(",,,%d,%d" % tuple([int(round(x * (10**6))) for x in latlong]))        
         return res['current_conditions']['condition']
     except:
         return u""
开发者ID:regevs,项目名称:dtour,代码行数:11,代码来源:weather.py


示例17: getData

def getData():
    """
	gets the weather at the specified location.
	"""

    try:
        googleWeather = pywapi.get_weather_from_google(location)
        condition = googleWeather["current_conditions"]["condition"]
        temp = googleWeather["current_conditions"]["temp_c"]
        return '<weather location="' + location + '" condition="' + condition + '" temp="' + temp + "c" + '"/>'
    except:
        return ""
开发者ID:dcellucci,项目名称:hu,代码行数:12,代码来源:hu_googleweather.py


示例18: main

def main(l, argv):
	argv = ' '.join(argv)
	try:
		google_result = pywapi.get_weather_from_google(argv)
		condition = string.lower(google_result['current_conditions']['condition'])
		temp = google_result['current_conditions']['temp_f']
		city = google_result['forecast_information']['city']
		result = 'It is currently %s and %sF in %s.' % (condition, temp, city)
	except Exception:
		result = 'Invalid location'

	return result.encode('ascii', 'replace')
开发者ID:kryptn,项目名称:icvbot,代码行数:12,代码来源:weather.py


示例19: getData

def getData():
	"""
	gets the weather at the specified location.
	"""
	
	try:
		googleWeather = pywapi.get_weather_from_google(location)
		condition = googleWeather['current_conditions']['condition']
		temp = googleWeather['current_conditions']['temp_c']
		return "<weather location=\"" + location + "\" condition=\"" + condition + "\" temp=\"" + temp + "c" + "\"/>"
	except:
		return ""
开发者ID:GunioRobot,项目名称:hu,代码行数:12,代码来源:hu_googleweather.py


示例20: fetchWeatherGoogle

def fetchWeatherGoogle():
    """ every 300 calls check the weather """
    global g_google_result
    global g_google_cnt

    if g_google_cnt==0:
        try:
            tmp = pywapi.get_weather_from_google('10025')
            print "Google read: %s" % tmp
            g_google_result = tmp
        except:
            pass 
    g_google_cnt = (g_google_cnt+1) % 300   
开发者ID:BrzTit,项目名称:dangerous-prototypes-open-hardware,代码行数:13,代码来源:twatch-weather&time.py



注:本文中的pywapi.get_weather_from_google函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pywapi.get_weather_from_weather_com函数代码示例发布时间:2022-05-27
下一篇:
Python pyvttbl.DataFrame类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap