async def get_weather(self): weather_client = python_weather.Client(format=python_weather.IMPERIAL) weather = await weather_client.find("78705") status = discord.Game(name=f"{weather.current.temperature}°F") # status = discord.Activity(type=discord.ActivityType.custom, name=f"{weather.current.temperature}°F") await self.bot.change_presence(activity=status) await weather_client.close()
async def get_weather(location): client = python_weather.Client(format=python_weather.METRIC) weather = await client.find(location) current_temperature = int((weather.current.temperature - 32) * 5/9) return_text = f"Current temperature in {location} is {current_temperature}°C" \ f"\n\nThe forecast temperature for the next 5 days will be: \n" for forecast in weather.forecasts: temp = int((forecast.temperature-32)*5/9) return_text += f"Date: {forecast.date.date()}, Sky: {forecast.sky_text}, Temperature: {temp}°C\n" await client.close() return return_text
async def run_james(): try: command = take_command() if 'play' in command: song = command.replace('play', '') talk('playing' + song) pywhatkit.playonyt(song) elif 'time' in command: time = datetime.datetime.now().strftime('%I:%M %p') talk('The current time is ' + time) elif 'what is the weather in' in command: weather_client = python_weather.Client( format=python_weather.IMPERIAL) city = command.replace('what is the weather in', '') weather = await weather_client.find(city) talk('The current temperature in ' + city + ' is ' + str(weather.current.temperature)) talk('The forecast') for forecast in weather.forecasts: fc_string = "The forecast for {} is {} and {} degrees.".format( forecast.date, forecast.sky_text, str(forecast.temperature)) talk(fc_string) await weather_client.close() elif 'what is' in command: term = command.replace('what is', '') info = pywhatkit.info(term, 3, True) talk(info) elif 'who is' in command: person = command.replace('who is', '') info = pywhatkit.info(person, 3, True) talk('searching wikipedia for ' + person) talk(info) elif 'search' in command: search_term = command.replace('search', '') talk('searching ' + search_term) pywhatkit.search(search_term) elif 'joke' in command: joke = pyjokes.get_joke() print(joke) talk(joke) elif 'close' in command: continueProgram = False else: talk("I did not understand you.") except: talk("Something went wrong. Try again.") pass
async def getweather(): # declare the client. format defaults to the metric system (celcius, km/h, etc.) client = python_weather.Client(format=python_weather.IMPERIAL) # fetch a weather forecast from a city weather = await client.find("Calgery Alberta") # returns the current day's forecast temperature (int) print(weather.current.temperature) # get the weather forecast for a few days for forecast in weather.forecasts: print(str(forecast.date), forecast.sky_text, forecast.temperature) # close the wrapper once done await client.close()
def get_current_weather(city, raw = False): # declare the client. format defaults to metric system (celcius, km/h, etc.) client = python_weather.Client() # fetch a weather forecast from a city weather = await client.find(city) # returns the current city temperature (int) if raw: return {"CurrentTemp": weather.current.temperature, "SkyCondition": weather.current.sky_text} else: print("The current temperature is" + str(weather.current.temperature) + "degrees Celcius") print("The weather condition is" + str(weather.current.sky_text)) await client.close()
async def get_raw_temp(): raw_api_dict = {} raw_api_dict['current'] = 0 raw_api_dict['humidity'] = 0 try: # declare the client. format defaults to metric system (celcius, km/h, etc.) client = python_weather.Client(format=python_weather.METRIC) # fetch a weather forecast from a city weather = await client.find(city_name) # close the wrapper once done await client.close() raw_api_dict['current'] = weather.current.temperature raw_api_dict['humidity'] = weather.current.humidity except: pass return raw_api_dict
async def get_weather(): try: # declare the client. format defaults to metric system (celcius, km/h, etc.) client = python_weather.Client(format=python_weather.IMPERIAL) # fetch a weather forecast from a city weather = await client.find("San Antonio") temp_celsius = weather.current.temperature temp_farenheit = int(conv_cel_to_fer(temp_celsius)) # returns the current day's forecast temperature (int) string = f"The current temperature today is {temp_farenheit} degrees fahrenheit in San Antonio" return string # get the weather forecast for a few days for forecast in weather.forecasts: print(str(forecast)) print(str(forecast.date), forecast.sky_text, forecast.temperature) # close the wrapper once done await client.close() return string except SystemExit: client.close()
async def main(): client = python_weather.Client(format=python_weather.IMPERIAL) try: weather = await client.find("Mountain View CA") now = datetime.datetime.today() forecast = find( lambda day: (day.date - now).days == N_DAYS_IN_ADVANCE_TO_NOTIFY, weather.forecast) assert forecast, ("Could not find forecasted day " f"{N_DAYS_IN_ADVANCE_TO_NOTIFY} days in advance. Forecast: " f"{weather.forecast}") if forecast.precip > PRECIP_THRESHOLD_PCT: message = get_message(forecast) print(message) send_email(message) else: print(f"Precip threshold not reached: {forecast.date} " f"{forecast.precip}") except Exception as e: send_email(f"Failed with {e}") finally: await client.close()
# import the module import python_weather # declare the client. format defaults to metric system (celcius, km/h, etc.) client = python_weather.Client(format=python_weather.IMPERIAL) # fetch a weather forecast from a city weather = client.find("Plymouth MI") # returns the current city temperature (int) #print(weather.current.temperature) # get the weather forecast for a few days for forecast in weather.forecast: print(str(forecast.date), forecast.sky_text, forecast.temperature) # close the wrapper once done client.close()