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 login(self): if self.login_data["apikey"]: self.client = ApixuClient(self.login_data["apikey"]) else: warnings.warn( 'MWP_WARNING. The "%s" Weather Package(WP) has not been \ properly activated due to the apikey' % (self.name.upper()))
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 getNowWeather(self, place=None): try: from apixu.client import ApixuClient, ApixuException client = ApixuClient(api_key) if not place: current = client.getCurrentWeather(q='Buea') else: current = client.getCurrentWeather(q=str(place)) cur_ = current['current'] self.pressure.text = str(cur_['pressure_mb']) + ' mb' self.tmp_value.text = str(cur_['temp_c']) + u'\u00b0' + ' C' self.temperature.text = str(cur_['temp_c']) + u'\u00b0' + ' C' self.humidity.text = str(cur_['humidity']) + '%' # self.sunrise.text = to be done self.visibility.text = str(cur_['vis_km']) + ' Km' self.local_time.text = str(current['location']['localtime']) self.precipitation.text = str(cur_['precip_mm']) + 'mm' self.feels.text = str(cur_['feelslike_c']) + u'\u00b0' + ' C' self.region.text = str(current['location']['region']) self.country.text = str(current['location']['country']) self.sky_state.text = str(cur_['condition']['text']) self.wind.text = str(cur_['wind_kph']) + 'kph' self.pressure.text = str(cur_['pressure_mb']) + 'mb' self.humidity.text = str(cur_['humidity']) except ConnectionError: ConErrorPop().open()
def run(self, dispatcher, tracker, domain): # from apixu.client import ApixuClient api_key = '6941d2731345403db6481426182012' client = ApixuClient(api_key) # # try: loc = tracker.get_slot('location') if loc != None: try: current = client.getCurrentWeather(q=loc) except: response = "Sorry I unable fetch weather, Some problem in fetching the data, Please retry or try some other location." dispatcher.utter_message(response) return [SlotSet('location',None)] # 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 = """Thanks for waiting.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) # response = 'testing' dispatcher.utter_message(response) return [SlotSet('location',None)] else: response = """Sorry ,I can't fetch,Please try someother location or rephases and type it""" dispatcher.utter_message(response) return [SlotSet('location',None)]
def gather_data(cursor, date, city): api_key = os.environ['APIXUKEY'] # print (api_key) client = ApixuClient(api_key) now = date history = client.history( q=city, since=datetime.date(now.year, now.month, now.day)) country = history['location']['country'] name = history['location']['name'] lat = history['location']['lat'] lon = history['location']['lon'] # print(history['forecast']['forecastday']) for day_forecast in history['forecast']['forecastday']: date = day_forecast['date'] avgtemp_c = day_forecast['day']['avgtemp_c'] cursor.execute(f'''INSERT INTO {TABLE_NAME} VALUES ( '{date}', '{name}', '{country}', {lat}, {lon}, {avgtemp_c} )''')
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = '1425533582cd4b6db2c20015192801' client = ApixuClient(api_key) loc = tracker.get_slot('location') forecast_date = tracker.get_slot('time') date_format = "%Y-%m-%d" today = time.strftime(date_format, time.localtime()) if forecast_date is not None: forecast_date = forecast_date[:10] else: forecast_date = today delta = datetime.strptime(forecast_date, date_format) - datetime.strptime(today, date_format) forecast_weather = {} try: forecast_weather = client.forecast(q=loc, days=delta.days + 1) except ApixuException as e: print(e.message) dispatcher.utter_message('No matching location found. Please try again') forecast = [weather for weather in forecast_weather['forecast']['forecastday'] if forecast_date in weather.values()] city = forecast_weather['location']['name'] condition = forecast[0]['day']['condition']['text'] temperature_c = forecast[0]['day']['avgtemp_c'] response = f'The weather in {city} is {condition}, the temperature is {temperature_c}.' dispatcher.utter_message(response) return [SlotSet('location', loc)]
def get_weather_data(place): client = ApixuClient(apixukey) try: current = client.getCurrentWeather(q=place) res = place, get_temp(current) except ApixuException: res = None return res
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = '...' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getcurrent(q=loc) link = current
def get_today(self): client = ApixuClient(self.api_key) current = client.getForecastWeather(q=self.city, days=1) high = current['forecast']['forecastday'][0]['day']['maxtemp_f'] low = current['forecast']['forecastday'][0]['day']['mintemp_f'] average = current['forecast']['forecastday'][0]['day']['avgtemp_f'] description = current['forecast']['forecastday'][0]['day'][ 'condition']['text'] return high, low, average, description
def forecast_weather(args): _city, _country_code = get_loc() client = ApixuClient("cc33a1e3237a4b78b3174104190206") forecast = client.forecast(q=f'{ _city},{_country_code}', days=7) print(f"{'Date':^12}|{'Min Temp':^10}|{'Max Temp':^10}|{'Condition':^15}") print(f"{'*'*47:^47}") for day in forecast['forecast']['forecastday']: print(f"{day['date']:^12}|{day['day']['mintemp_c']:^10}|{day['day']['maxtemp_c']:^10}|{day['day']['condition']['text']:^15}")
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 test_history(): api_key = os.environ['APIXUKEY'] client = ApixuClient(api_key) now = datetime.datetime.now() history = client.history( q='London', since=datetime.date(now.year, now.month, now.day), until=datetime.date(now.year, now.month, now.day), ) validate(history, schema.read("history.json"))
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = '5ed103a862bd442182385105181306' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(q=loc) city = current['location']['name'] condition = current['current']['condition']['text'] response = """It is currently {} in {} at the moment.""".format( condition, city) dispatcher.utter_message(response) return [SlotSet('location', loc)]
def getApixu(ApiKey): # create the Apixu client obj & query current & 7 forecast weather data try: client = ApixuClient(ApiKey) # these weather are in a dict form [json] currentWeather = client.getCurrentWeather(q = "Harare") # get current weather for Hre forecastWeather = client.getForecastWeather(q = "Harare", days = 7) # get weather forecast for Hre return True, currentWeather, forecastWeather except ApixuException as e: return False, "[!] Error querying data {}".format(e.message)
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 = "d1881979fb4d4ee4879110427182103" client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperatur = current['current']['temp_c'] humudity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """ It is currently {} in {} at the moment. The remperatur is {} degrees, the humidity is {}% and wind speed is {} mph. """.format(condition, city, temperatur, humudity, 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 = '8cf4dc262c664ae59b0223043183010' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(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 = '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 = "ed0b641d57bb4629a5c140954181509" client = ApixuClient(api_key) loc = tracker.get_slot("location") current = client.getCurrentWeather(q=loc) 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): api_key = "9b14178e623944e4b3631246181904" client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(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'] windspeed = current['current']['wind_mph'] response = """It is currently {} in {} at the moment. The temperature " \ "is {} degrees, humidity is {}% and the wind speed is {} mph""".format(condition, city, temperature_c, humidity, windspeed) dispatcher.utter_message(response) return [SlotSet('location',loc)]
def run(self, dispactcher, tracjer, diomain): from apixu.client import ApixuClient api_key = 'b745deea711a4936975221117191208' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temprature_c = current['current']['temp_c'] humidity = current['current']['humidity'] wind_mph = current['current']['wind_mph'] response = """It is currentlu {} in {} at the moment. The temprature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format( condition, city, temprature_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 = 'a591d9dd033743b79a3175250191806' #your apixu key client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getcurrent(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 = 'a2a1f7505d534755929211912181705' client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(q=loc) # the response is a dictionnary 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 = '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 = config("APIXU_KEY") client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(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 = f"""It is currently {condition} in {city}, {country}. The temperature is {temperature_c} degrees, the humidity is {humidity}% and the wind speed is {wind_mph} mph.""" dispatcher.utter_message(response) return [SlotSet('location', loc)]
def weather(self, irc, msg, args, place): '''<place> Current weather for a <place>. ''' api_key = self.registryValue('api_key') if not api_key: irc.error( 'The API key is missing. ' 'Please configure the plugins.Weather.api_key directive.', Raise=True, ) place = place.lower() if place in Weather.PLACES: place = Weather.PLACES[place] try: client = ApixuClient(api_key) response = client.getCurrentWeather(q=place) last_updated = datetime.fromtimestamp( response['current']['last_updated_epoch'], ).strftime('%Y-%m-%d %H:%M') irc.reply( 'The current temperature in {l[name]}, ' '{l[country]} is {w[temp_c]} °C ' '(feels like {w[feelslike_c]} °C). ' 'Conditions: {w[condition][text]}. ' 'Humidity: {w[humidity]} %. ' 'Wind: {w[wind_dir]} {w[wind_kph]} km/h ({d}).'.format( w=response['current'], l=response['location'], d=last_updated, ) ) except Exception as e: irc.error(unicode(e))
def run(self, dispatcher, tracker, domain): from apixu.client import ApixuClient api_key = '1499cd68946d4387b6c175525181806' # your apixu key client = ApixuClient(api_key) loc = tracker.get_slot('location') current = client.getCurrentWeather(q=loc) country = current['location']['country'] city = current['location']['name'] condition = current['current']['condition']['text'] temperature_c = current['current']['temp_c'] feelslike_c = current['current']['feelslike_c'] humidity = current['current']['humidity'] wind_kph = current['current']['wind_kph'] response = """It is currently {} in {}/{} at the moment. \nThe temperature is {} oC feels like {} oC.\n The humidity is {}% and the wind speed is {} kph.""".format( condition, city, country, temperature_c, feelslike_c, humidity, wind_kph) dispatcher.utter_message(response) return [SlotSet('location', loc)]
from apixu.client import ApixuClient, ApixuException import MySQLdb api_key = 'GET YOU API KEY FROM APIXU.COM' client = ApixuClient(api_key) db = MySQLdb.connect("localhost", "root", "", "zambia_weather") cursor = db.cursor() # Town names array, helps to grab the data for each specific town. towns_one = ['Chadiza', 'Chama', 'Chavuma', 'Chembe', 'Chibombo', 'Chiengi', 'Chililabombwe', 'Chilubi', 'Chingola', 'Chinsali'] towns_two = ['Chipata', 'Chirundu', 'Choma', 'Gwembe', 'Isoka', 'Kabwe', 'Kafue', 'Kalabo'] towns_three = ['Kalomo', 'Kaoma', 'Kapiri', 'Kasama', 'Kasempa', 'Kataba', 'Katete', 'Kawambwa', 'Kazembe'] towns_four = ['Kazungula', 'Kitwe', 'Livingstone', 'Luangwa', 'Luanshya', 'Lukulu', 'Lundazi'] towns_five = ['Lusaka', 'Maamba', 'Makeni', 'Mansa', 'Mazabuka', 'Mbala', 'Mbereshi', 'Milenge'] towns_six = ['Mkushi', 'Mongu', 'Monze', 'Mpika', 'Mporokoso', 'Mpulungu', 'Mufulira', 'Mumbwa', 'Muyombe'] towns_seven = ['Mwinilunga', 'Nchelenge', 'Ndola', 'Ngoma', 'Nkana', 'Pemba', 'Petauke', 'Samfya', 'Senanga'] towns_eight = ['Serenje', 'Sesheke', 'Shiwa', 'Ngandu', 'Siavonga', 'Sikalongo', 'Sinazongwe', 'Solwezi', 'Zambezi', 'Zimba'] towns = towns_one + towns_two + towns_three + towns_four + towns_five + towns_six + towns_seven + towns_eight for x in towns: print x current = client.getCurrentWeather(q=x) tables = """CREATE TABLE IF NOT EXISTS %s ( `id` int(11) NOT NULL AUTO_INCREMENT, `cloud` int(5) DEFAULT NULL, `condition_text` varchar(20) DEFAULT NULL, `condition_code` int(5) DEFAULT NULL, `icon` text, `temperature` float DEFAULT NULL, `humidity` int(5) DEFAULT NULL,
def test_getCurrentWeather_no_api_key(self): client = ApixuClient() with self.assertRaises(ApixuException) as cm: client.getCurrentWeather() self.assertEqual(cm.exception.code, 1002)
def test_getCurrentWeather_invalid_api_key(self): client = ApixuClient('INVALID_KEY') with self.assertRaises(ApixuException) as cm: client.getCurrentWeather() self.assertEqual(cm.exception.code, 2006)