本文整理汇总了Python中pyowm.OWM属性的典型用法代码示例。如果您正苦于以下问题:Python pyowm.OWM属性的具体用法?Python pyowm.OWM怎么用?Python pyowm.OWM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pyowm
的用法示例。
在下文中一共展示了pyowm.OWM属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def __init__(self, apikey, location, metric):
self.apikey = apikey
self.location = location
self.metric = metric
self.temperature_unit = "celsius" if metric else "fahrenheit"
self.speed_unit = "meters_sec" if metric else "miles_hour"
self.starttime = time.time()
self.client = pyowm.OWM(self.apikey)
self.temp = None
self.wind_speed = None
self.wind_dir = None
self.conditions = None
self.icon_name = None
# Remember if the API key was invalid so we don't keep trying to make calls with it
self.apikey_valid = True
# Force an update for our initial data
self.update(True)
# Return true if we have valid weather data available.
# If we have a valid temp, we should be able to assume wind/conditions also exist
示例2: weather
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def weather():
lat, lan = getLatLan()
if not lat:
return 0, 0, 0, "- -"
else:
owm = pyowm.OWM('c84c2f255787c9dfc3d1c8b3795e4686')
observation = owm.weather_at_coords(lat, lan)
w = observation.get_weather()
tmp = w.get_temperature('celsius')
return tmp['temp'], w.get_humidity(), w.get_wind()['speed'], w.get_status()
示例3: __init__
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def __init__(self, apikey, location, log = None, unit = 'imperial'):
super(MyWeather, self).__init__()
self.APIKey = apikey
self.log = log
self.Location = location
self.OWM = None
self.Observation = None
self.WeatherUnit = unit
self.WeatherData = None
self.ObservationLocation = None
self.DataAccessLock = threading.Lock() # lock to synchronize access to WeatherData
if not pyowm_installed:
self.LogError("Library pyowm not installed, disabling weather support." )
return
try:
if self.APIKey != None:
self.APIKey = self.APIKey.strip()
if self.Location != None:
self.Location = self.Location.strip()
if self.APIKey == None or not len(self.APIKey) or self.Location == None or not len(self.Location):
self.LogError("Weather API key invalid or Weather Location invalid")
return
self.InitOWM()
self.Threads["WeatherThread"] = MyThread(self.WeatherThread, Name = "WeatherThread")
except Exception as e1:
self.LogErrorLine("Error on MyWeather:init: " + str(e1))
#---------------------GetUnits----------------------------------------------
示例4: InitOWM
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def InitOWM(self):
try:
self.OWM = pyowm.OWM(self.APIKey) # You MUST provide a valid API key
return True
except Exception as e1:
self.OWM = None
self.LogErrorLine("Error in InitOWM: " + str(e1))
return False
#---------------------WeatherThread-----------------------------------------
示例5: GetObservation
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def GetObservation(self):
if self.OWM == None:
self.Observation = None
self.ObservationLocation = None
return
try:
if self.Location.isdigit():
if len(self.Location.strip()) == 5: # Assume this is a zip code
self.Observation = self.OWM.weather_at_zip_code(self.Location,"us")
else:
self.Observation = self.OWM.weather_at_id(int(self.Location))
else:
self.Observation = self.OWM.weather_at_place(self.Location)
self.ObservationLocation = self.Observation.get_location()
except Exception as e1:
self.Observation = None
self.ObservationLocation = None
self.LogErrorLine("Error in GetObservation: " + "(" + str(self.Location) + ") : " + str(e1))
#---------------------WeatherThread-----------------------------------------
示例6: WeatherThread
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def WeatherThread(self):
time.sleep(1)
while True:
if self.OWM == None:
if not self.InitOWM():
if self.WaitForExit("WeatherThread", 60 ): # 60 sec
return
continue
try:
self.GetObservation()
if self.Observation == None:
self.OWM = None
if self.WaitForExit("WeatherThread", 60 ): # 60 sec
return
continue
weatherdata = self.Observation.get_weather()
with self.DataAccessLock:
self.WeatherData = weatherdata
except Exception as e1:
self.LogErrorLine("Error calling Observation.get_weather: " + str(e1))
self.WeatherData = None
if self.WaitForExit("WeatherThread", 60 ): # 60 sec
return
continue
if self.WaitForExit("WeatherThread", 60 * 10): # ten min
return
#---------------------GetLocation-------------------------------------------
示例7: __init__
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def __init__(self, *args):
super(WeatherReportModule, self).__init__(*args)
self.api_key = self.get_configuration("open_weather_map_api_key")
if self.api_key:
self.owm = pyowm.OWM(self.api_key)
else:
return False
self.city = self.get_configuration(section="USER", key="city")
self.num_service = NumberService()
# def weather_information(self):
# self.assistant.say("What would you like to know about?")
# query = self.assistant.listen().decipher()
示例8: weather_main
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def weather_main(event):
'''Get the users weather from the infromation in the users database'''
log.info("This function is {0}".format(weather_main))
response = {"type": "success", "text": None, "data": {}}
db = event["db"]
username = event["username"]
user_table = db["users"].find_one(username=username)
if (user_table["city"] and user_table["country"]):
if user_table["state"]:
fetch_str = "{0}, {1}".format(user_table["city"], user_table["state"])
else:
fetch_str = "{0}, {1}".format(user_table["city"], user_table["country"])
pyowm_key = tools.load_key("pyowm", db)
owm = pyowm.OWM(pyowm_key)
observation = owm.weather_at_place(fetch_str)
w = observation.get_weather()
status = w.get_detailed_status()
temp_sym = "F"
if "temp_unit" in user_table.keys():
user_temp_unit = user_table["temp_unit"]
temperature = w.get_temperature(user_temp_unit)
if user_temp_unit == "celsius":
temp_sym = "C"
else:
temperature = w.get_temperature('fahrenheit')
weather_str = "Weather for {0} is {1}, with a temperature of {2} {3}".format(
fetch_str, status, temperature["temp"], temp_sym)
response["text"] = weather_str
else:
response["type"] = "success"
command_id = event["command_id"]
session_id = event["session"]["id"]
response["text"] = "What city are you in?"
#Add a pointer to this function to the event, because for some reason the code in the above function can't find it
tools.set_response(session_id, command_id, event, ask_country)
response["data"] = {"response": command_id}
return response
示例9: config_complete
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def config_complete(self):
self._owm = pyowm.OWM(self.config["API_KEY"])
示例10: weather
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def weather():
lat, lan = getLatLan()
if not lat:
return 0, 0, 0, "- -"
else:
owm = pyowm.OWM('ENTER KEY HERE')
observation = owm.weather_at_coords(lat, lan)
w = observation.get_weather()
tmp = w.get_temperature('celsius')
return tmp['temp'], w.get_humidity(), w.get_wind()['speed'], w.get_status()
示例11: __init__
# 需要导入模块: import pyowm [as 别名]
# 或者: from pyowm import OWM [as 别名]
def __init__(self, api_key: str, city_id: int) -> None:
self.owm = OWM(api_key)
self._city_id = city_id
self._unit = 'celsius'
self._current_weather = (0, 0.0, 0.0, 0.0, 0.0)
self._forecast: List[Tuple[int, float, float, float, float]] = []