当前位置: 首页>>代码示例>>Python>>正文


Python pywapi.get_weather_from_google函数代码示例

本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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