def run(self, dispatcher, tracker, domain): # weather = Weather(unit=Unit.CELSIUS) # gpe = ('Auckland', tracker.get_slot('GPE'))[bool(tracker.get_slot('GPE'))] # result = weather.lookup_by_location(gpe) # if result: # condition = result.condition # city = result.location.city # country = result.location.country # dispatcher.utter_message('It\'s ' + condition.text + ' and ' + condition.temp + '°C in ' + # city + ', ' + country + '.') # else: # dispatcher.utter_message('We did not find any weather information for ' + gpe + '. Search by a city name.') #dispatcher.utter_message('Its quite hot') from apixu.client import ApixuClient api_key = '0191841c0d7a4a91b81115516191404' client = ApixuClient(api_key) loc = tracker.get_slot('GPE') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format( condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) return
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient # You need to provide APIXUKEY in file export_APIXU_KEY.sh since it won't be saved in GIT # # http://api.apixu.com/v1/current.json?key=<apixu_key...>&q=paris try: #print(os.environ) print("APIXU_KEY=" + os.environ["APIXU_KEY"]) api_key = os.environ['APIXU_KEY'] # api_key = 'xxxx' #your apixu key client = ApixuClient(api_key) except KeyError: print("Please set the environment variable APIXU_KEY") os.sys.exit(1) loc = tracker.get_slot('location') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph."""\ .format(condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) return [SlotSet('location',loc)]
def get_weather(self, location: Text) -> Dict: from apixu.client import ApixuClient api_key = "da0041cd4e0a4ddbaef73702191507" client = ApixuClient(api_key=api_key, lang="en") try: current = client.current(q=location) return current except Exception as e: return None
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = 'd47a4f7a5bc84662ac0113212193107' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.current(q=loc) #country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format( condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) return [SlotSet('location', loc)] '''
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = '2ba4cf94bbc2427791294257191205' #your apixu key client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph) ##loc = tracker.get_slot('location') ##response = "weather is absolutely fantastic" dispatcher.utter_message(response) return [SlotSet('location',loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = 'c3e1096f0ccc478cb40101824192704' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['humidity'] humidity = current['current']['humidity'] response = """It is currently {} in {} at the moment.The temperature is {} degrees.""".format( condition, city, temperature_c) dispatcher.utter_message(response) return [SlotSet('location', loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = 'c3488dbfdd024eda80e65216192603' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.current(q=loc) print("Current is :", current) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = f"""It is currently {condition} in {city} as of now.The temparature is {temperature_c} degree celsius. The humidity is {humidity}% and the wind speed is {wind_mph}.""" dispatcher.utter_message(response) return [SlotSet('location', loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = 'f5d0a214ccf44880ace61427180103' #your apixu key client = ApixuClient(api_key) loc = tracker.get_slot('GPE') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format( condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) return [SlotSet('GPE', loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_Key = '6b89f2fd6e6f46ddab9144134190908' client = ApixuClient(api_Key) loc = tracker.get_slot('location') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """it is currently {} in {} at the moment the temperature is {} degrees, the humidity is {} and the wind speed is {} mph""".format( condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) return [SlotSet('location', loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = '6c1e6bbee4404ae280663137190209' #your apixu key client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] # It is currently Partly cloudy in Colombo at the moment. The temperature is 28.0 degrees, the humidity is 84% and the wind speed is 8.1 mph. response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format( condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) return [SlotSet('location', loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = 'f7d8a7805fb74e22bff182510192804' # your apixu key client = ApixuClient(api_key) loc = tracker.get_slot('location') #current = client.getcurrent(q=loc) current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format( condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) #dispatcher.utter_message('test test') return [SlotSet('location', loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient #your apixu key from apixu api_key = 'e15324bff6e34eac8cb75040191105' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.current(loc) print(current) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format( condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) return [SlotSet('location', loc)]
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = '' #your apixu key client = ApixuClient(api_key) try: loc = tracker.get_slot('location') current = client.current(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph) dispatcher.utter_message(response) except: dispatcher.utter_message("Something went wrong. Unable to get details of the weather. Please try again!") return [SlotSet('location',loc)]
def validate_weather_location( self, value: Text, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> Optional[Text]: """Validate location value.""" from apixu.client import ApixuClient cur_loc = tracker.get_slot("weather_location") dispatcher.utter_message(str(cur_loc)) api_key = "your_api_key" client = ApixuClient(api_key=api_key, lang="en") try: current = client.current(q=value) self.condition = current["current"]["condition"]["text"] self.degree = current["current"]["temp_c"] dispatcher.utter_message(str(self.condition) + str(self.degree)) return {"weather_location": value} except Exception as e: dispatcher.utter_template("utter_no_location", tracker) return {"weather_location": None}
def test_current(): api_key = os.environ['APIXUKEY'] client = ApixuClient(api_key) current = client.current('London') validate(current, schema.read('current.json'))
import os from apixu.client import ApixuClient api_key = os.environ['APIXUKEY'] client = ApixuClient(api_key=api_key, lang="fr") current = client.current(q='London') print(current['location']['name']) print(current['location']['region']) print(current['current']['last_updated_epoch']) print(current['current']['condition']['text']) ''' { "location":{ "name":"London", "region":"City of London, Greater London", "country":"United Kingdom", "lat":51.52, "lon":-0.11, "tz_id":"Europe/London", "localtime_epoch":1548103139, "localtime":"2019-01-21 20:38" }, "current":{ "last_updated_epoch":1548102624, "last_updated":"2019-01-21 20:30", "temp_c":4.0, "temp_f":39.2,
def test_current_invalid_api_key(self): client = ApixuClient('INVALID_KEY') with self.assertRaises(ApixuException) as cm: client.current() self.assertEqual(cm.exception.code, errors.API_KEY_INVALID)
def test_current_no_api_key(self): client = ApixuClient() with self.assertRaises(ApixuException) as cm: client.current() self.assertEqual(cm.exception.code, errors.API_KEY_NOT_PROVIDED)
import os from dotenv import dotenv_values from apixu.client import ApixuClient os.environ.update(dotenv_values()) api_key = os.environ['APIXUKEY'] client = ApixuClient(api_key) query = 'London' current = client.current(q=query) print(current['location'])