def run(self, dispatcher, tracker, domain): import requests url = 'https://icanhazdadjoke.com/' headers = {'Accept': 'application/json'} joke_msg = requests.get(url, headers=headers).json().get('joke') dispatcher.utter_message(joke_msg) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): # Use VLC to play import requests from bs4 import BeautifulSoup import re artist = str(tracker.get_slot('artist')) song = str(tracker.get_slot('song')) if artist == 'None': artist = '' search = "https://www.youtube.com/results?search_query=song+"+artist.replace(' ', '+').replace('\'', '')\ + "+"+song.replace(' ', '+').replace('\'', '') source_code = requests.get(search) plain_txt = source_code.text soup = BeautifulSoup(plain_txt, 'html.parser') regex = re.compile(r'/watch\?v=.*') # print(search) url = '' for vid in soup.findAll('a', {'class': 'yt-uix-sessionlink spf-link'}, href=True): if regex.search(vid['href']): url = 'https://www.youtube.com' + str(vid['href']) dispatcher.utter_message("Playing: " + url) break video = pafy.new(url) best = video.getbestaudio() playurl = best.url Instance = vlc.Instance() media = Instance.media_new(playurl) media.get_mrl() player.set_media(media) player.play() return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): try: output_sun = tracker.get_slot("output_sun") ouput_time = tracker.get_slot("ouput_time") output_people = tracker.get_slot("output_people") output_date = tracker.get_slot("output_date") name = tracker.get_slot("name") phone_num = tracker.get_slot("phone_num") end = tracker.get_slot("end") if end: if end.replace(" ", "") == "輸出表單": dispatcher.utter_message( f"連絡人:{name.replace(' ', '')}\n" f"用餐人數:{output_people}\n" f"連絡電話:{phone_num.replace(' ', '')}\n" f"用餐日期:{output_date}\n" f"用餐時間:{ouput_time}\n" f"用餐時段:{output_sun}") return [AllSlotsReset()] except Exception as e: logging.error(str(e)) return [ SlotSet("output_sun", output_sun if output_sun is not None else []), SlotSet("ouput_time", ouput_time if ouput_time is not None else []), SlotSet("output_people", output_people if output_people is not None else []), SlotSet("output_date", output_date if output_date is not None else []), SlotSet("name", name if name is not None else []), SlotSet("phone", phone_num if phone_num is not None else []) ]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = "database mgmt,OS,Hardware,messaging,application server,log,Integration,Business intelligence" dispatcher.utter_message( "These are the product groups maintained by the app:") dispatcher.utter_message(response) return [AllSlotsReset()]
def submit(self, dispatcher, tracker, domain): # type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict] """Define what the form has to do after all required slots are filled""" # utter submit template dispatcher.utter_template('utter_search_template', tracker) dispatcher.utter_message( "{},在{}发生一起性质恶劣的{},引起全市人民的高度关注,以下是详细信息:".format( tracker.get_slot("day"), tracker.get_slot("place"), tracker.get_slot("case"))) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): item = tracker.get_slot("item") item = extract_item(item) if item is None: dispatcher.utter_message("您好,我现在只会查话费和流量") dispatcher.utter_message("你可以这样问我:“帮我查话费”") return [AllSlotsReset()] time = tracker.get_slot("time") if time is None: dispatcher.utter_message("您想查询哪个月的消费?") return [] # query database here using item and time as key. but you may normalize time format first. dispatcher.utter_message("好,请稍等") if item == "流量": dispatcher.utter_message("您好,您{}共使用{}二百八十兆,剩余三十兆。".format( time, item)) else: dispatcher.utter_message("您好,您{}共消费二十八元。".format(time)) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): make = tracker.get_slot('make') model = tracker.get_slot('model') model_year = tracker.get_slot('model_year') user_age = tracker.get_slot("user_age") license_exp = tracker.get_slot("license_exp") print(make) print(model) print(model_year) print(user_age) print(license_exp) dispatcher.utter_message('Your car insurance pricing should be: 100$') return [Restarted(), AllSlotsReset()]
def run(self, dispatcher, tracker, domain): email = tracker.get_slot('email') global email_response global app_response s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login("*****@*****.**", "test1234@1") message = "The details of all the restaurants you inquried: \n \n" message += email_response message = 'Subject: {}\n\n{}'.format("Foodie says Hi !!", message) try: s.sendmail("*****@*****.**", str(email), message) s.quit() except: dispatcher.utter_message(email) email_response = "" app_response = "" return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): email = tracker.get_slot('email') import smtplib s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login("*****@*****.**", "Upgrad@2019") message = "The details of all the restaurants you inquried \n \n" global result_of_last_query message = message + result_of_last_query try: s.sendmail("*****@*****.**", str(email), message) s.quit() except: dispatcher.utter_message(email) result_of_last_query = "" return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): try: end = tracker.get_slot("end") name = tracker.get_slot("name") occupation = tracker.get_slot("occupation") old = tracker.get_slot("old") income = tracker.get_slot("income").replace(" ", "") h_price = tracker.get_slot("h_price").replace(" ", "") self_rent = tracker.get_slot("self_rent").replace(" ", "") rate = tracker.get_slot("rate") percent = tracker.get_slot("percent") real_rent = tracker.get_slot("real_rent") need_money = tracker.get_slot("need_money") print(tracker.current_slot_values()) if end: if end.replace(" ", "") == "輸出表單": dispatcher.utter_message(f"姓名:{name}\n" f"年齡:{old}\n" f"職業:{occupation}\n" f"月收入: {income}\n" f"可貸利率:利率{rate}%\n" f"最高貸款比例:{percent}%\n" f"申請者實際可貸款金額:{real_rent}萬元\n" f"房屋總價:{h_price}\n" f"自備首付款:{self_rent}\n" f"仍需求湊金額:{need_money}萬\n") return [AllSlotsReset()] except Exception as e: logging.error(str(e)) return [ SlotSet("name", name if name is not None else []), SlotSet("occupation", occupation if occupation is not None else []), SlotSet("old", old if old is not None else []), SlotSet("income", income if income is not None else []), SlotSet("h_price", h_price if h_price is not None else []), SlotSet("self_rent", self_rent if self_rent is not None else []), SlotSet("real_rent", real_rent if real_rent is not None else []), SlotSet("rate", rate if rate is not None else []), SlotSet("percent", percent if percent is not None else []), SlotSet("need_money", need_money if need_money is not None else []) ]
def run(self, dispatcher, tracker, domain): email = tracker.get_slot('email') # for slack handling if len(email.split("|")) == 2: email = email.split("|")[1] #import smtplib #s = smtplib.SMTP('smtp.gmail.com', 587) #s.starttls() #s.login("<src_email_id>", "<password>") message = "The details of all the restaurants you inquried \n \n" global result_of_last_query message = message + result_of_last_query try: mm.SendEmail(email,message) except: dispatcher.utter_message(email) result_of_last_query = "" return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): email = tracker.get_slot('email') # for slack handling if len(email.split("|")) == 2: email = email.split("|")[1] import smtplib s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login("*****@*****.**", "likhil09") message = "The details of all the restaurants you inquried \n \n" global result_of_last_query message = message + result_of_last_query try: s.sendmail("*****@*****.**", str(email), message) s.quit() except: dispatcher.utter_message(email) result_of_last_query = "" return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = "1660 is the peoples cost." dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = "No" dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = " The app sponsor signoff status is Complete" dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = " The app provider is robert" dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = " The app release date is 25-1-2019" dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = "oracle,sybase,Linux,Linux,HP,IBM,Java,splunk" dispatcher.utter_message("These are the app products") dispatcher.utter_message(response) return [AllSlotsReset()]
def submit(self, dispatcher, tracker, domain): """Define what the form has to do after all required slots are filled""" try: date = tracker.get_slot("date") sun = tracker.get_slot("sun") time = tracker.get_slot("time") num = tracker.get_slot("num") num = "".join(re.findall(r'[0-9]+', num)) output_sun = f"" print(tracker.current_slot_values()) print(num) date_num = re.findall(r'[0-9]+[.]*[0-9]*', date) if sun.find("晚") >= 0: output_sun = f"晚餐" else: output_sun = f"午餐" num_dict = { "1": "一", "2": "兩", "3": "三", "4": "四", "5": "五", "6": "六", "7": "七", "8": "八", "9": "九", "10": "十" } sql_1 = f"SELECT * FROM restaurant_table WHERE 日期 = '2020/{date_num[0]}/{date_num[1]}' AND 時段 = '{output_sun}'" con = sqlite3.connect('SQL/restaurant.db') cur = con.cursor() cur.execute(sql_1) rows = cur.fetchall() output_date = f"{date_num[0]}月{date_num[1]}日星期{rows[0][1]}" output_people = f"{num}人" ouput_time = f"{time_change(time, sun)}" if float(num) <= 2 and float(rows[0][3]) > 0: dispatcher.utter_message( f"沒問題,跟您確定一下,訂位時間: {date_num[0]}月{date_num[1]}日星期{rows[0][1]}{sun}{time},共{num_dict[num]}位。" ) elif float(num) <= 4 and float(rows[0][4]) > 0: dispatcher.utter_message( f"沒問題,跟您確定一下,訂位時間: {date_num[0]}月{date_num[1]}日星期{rows[0][1]}{sun}{time},共{num_dict[num]}位。" ) elif float(num) <= 10 and float(rows[0][5]) > 0: dispatcher.utter_message( f"沒問題,跟您確定一下,訂位時間: {date_num[0]}月{date_num[1]}日星期{rows[0][1]}{sun}{time},共{num_dict[num]}位。" ) else: dispatcher.utter_message(f"您訂的時間沒有空位,請問要改訂別的時間麻") cur.close() con.close() return [AllSlotsReset()] except Exception as e: logging.error(str(e)) finally: cur.close() con.close() return [ SlotSet("output_sun", output_sun if output_sun is not None else []), SlotSet("ouput_time", ouput_time if ouput_time is not None else []), SlotSet("output_people", output_people if output_people is not None else []), SlotSet("output_date", output_date if output_date is not None else []) ]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = " The owner of the app is john" dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): keyword = tracker.get_slot('keyword') location = tracker.get_slot('location') df = pd.read_csv("location.csv") message = tracker.latest_message['text'] words = message.split() for word in words: if word in df['Community Name']: SlotSet("location", word) location = tracker.get_slot('location') try: g = geocoder.geonames(location, key='h1554184') except: g='' names = [] links = [] table= [] if keyword != 'null' and location != 'null': r = requests.get('https://search.communidata.at/odgraphsearch/api/v1/get/datasets?limit=10&l=gn:'+str(g.geonames_id)+'&q='+keyword) response = r.json() if len(response['hits']['hits'])==0: response_bot = 'Sorry, it looks like we don\'t have that! Try to enter other keywords.' else: if len(response['hits']['hits'])>5: therange = 5 else: therange = len(response['hits']['hits']) for i in range(therange): name = response['hits']['hits'][i]['_source']['dataset']['dataset_name'] names.append(name) link = response['hits']['hits'][i]['_source']['dataset']['dataset_link'] links.append(link) for i, e in zip(names,links): table.append([i,e]) response_bot = "Datasets with the keyword {} and within {}".format(keyword, location) + " " + tabulate(table, headers=['Name', 'Link']) elif keyword !='null': r = requests.get('https://search.communidata.at/odgraphsearch/api/v1/get/datasets?limit=10&q='+keyword) response = r.json() if len(response['hits']['hits'])==0: response_bot = 'Sorry, it looks like we don\'t have that! Try to enter other keywords.' else: if len(response['hits']['hits'])>5: therange = 5 else: therange = len(response['hits']['hits']) for i in range(therange): name = response['hits']['hits'][i]['_source']['dataset']['dataset_name'] names.append(name) link = response['hits']['hits'][i]['_source']['dataset']['dataset_link'] links.append(link) for i, e in zip(names,links): table.append([i,e]) response_bot = "Datasets with the keyword {}".format(keyword) + " " + tabulate(table, headers=['Name', 'Link']) elif location !='null' : r = requests.get('https://search.communidata.at/odgraphsearch/api/v1/get/datasets?limit=10&l=gn:'+str(g.geonames_id)) response = r.json() if len(response['hits']['hits'])==0: response_bot = 'Sorry, it looks like we don\'t have that! Try to enter other keywords.' else: if len(response['hits']['hits'])>5: therange = 5 else: therange = len(response['hits']['hits']) for i in range(therange): name = response['hits']['hits'][i]['_source']['dataset']['dataset_name'] names.append(name) link = response['hits']['hits'][i]['_source']['dataset']['dataset_link'] links.append(link) for i, e in zip(names,links): table.append([i,e]) response_bot = "Datasets within {}".format(location) +" "+ tabulate(table, headers=['Name', 'Link']) else: response_bot = 'Sorry, it looks like we don\'t have that! Try to enter other keywords.' dispatcher.utter_message(response_bot) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): #print(tracker.latest_message) dispatcher.utter_message("Sorry, didn't get that. Please try again.") return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): player.stop() dispatcher.utter_message("Music stopped") return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): night_time_dict = { "五點": "17:00", "六點": "18:00", "七點": "19:00", "八點": "20:00", "九點": "21:00", "十點": "22:00" } morning_time_dict = { "五點": "5:00", "六點": "6:00", "七點": "7:00", "八點": "8:00", "九點": "9:00", "十點": "10:00", "十一點": "11:00", "十二點": "12:00" } try: date = tracker.get_slot("date") # num = tracker.get_slot("num") car = tracker.get_slot("car") name = tracker.get_slot("name") start_sun = tracker.get_slot("start_sun") start_time = tracker.get_slot("start_time") start_location = tracker.get_slot("start_location") carname = tracker.get_slot("carname") end_sun = tracker.get_slot("end_sun") end_time = tracker.get_slot("end_time") end_location = tracker.get_slot("end_location") phone = tracker.get_slot("phone") rent_price = tracker.get_slot("rent_price") end = tracker.get_slot("end") if end: if end.replace(" ", "") == "輸出表單": if start_sun.find("晚上") >= 0: num_start_time = night_time_dict[start_time] else: num_start_time = morning_time_dict[start_time] if end_sun.find("晚上") >= 0: num_end_time = night_time_dict[end_time] else: num_end_time = morning_time_dict[end_time] dispatcher.utter_message( f"訂購人:{name}\n" f"連絡電話:{phone.replace(' ', '')}\n" f"訂購車款:{carname}\n" f"取車時間:{date[0]},{num_start_time}\n" f"取車地點:平安租車-{start_location}\n" f"還車時間:{date[1]},{num_end_time}\n" f"還車地點:平安租車-{end_location}\n" f"價格:{rent_price}元") return [AllSlotsReset()] except Exception as e: logging.error(str(e)) return [ SlotSet("date", date if date is not None else []), SlotSet("car", car if car is not None else []), SlotSet("name", name if name is not None else []), SlotSet("start_sun", start_sun if start_sun is not None else []), SlotSet("start_time", start_time if start_time is not None else []), SlotSet("start_location", start_location if start_location is not None else []), SlotSet("carname", carname if carname is not None else []), SlotSet("end_sun", end_sun if end_sun is not None else []), SlotSet("end_time", end_time if end_time is not None else []), SlotSet("end_location", end_location if end_location is not None else []), SlotSet("phone", phone if phone is not None else []), SlotSet("rent_price", rent_price if rent_price is not None else []) ]
def run(self, dispatcher, tracker, domain): AllSlotsReset() return [Restarted()]
class ActionGetDataset(Action): def name(self): return 'action_get_dataset' def run(self, dispatcher, tracker, domain): keyword_en = tracker.get_slot('keyword') if keyword_en == "null" and len(tracker.latest_message['text'].split()) <= 3: keyword_en = tracker.latest_message['text'].split()[0] translator = Translator() keyword = translator.translate(keyword_en, dest='de').text location = tracker.get_slot('location') df = pd.read_csv("location.csv") if location == 'null': message = tracker.latest_message['text'] words = message.split() for word in words: if df['Community Name'].str.contains(word, case=False).any(): location = word [SlotSet('location', word)] #filled_slots=str(tracker.current_slot_values()) try: g = geocoder.geonames(location, key='h1554184') except: g='' names = [] links = [] table= [] if keyword != 'null' and location != 'null': r = requests.get('https://search.communidata.at/odgraphsearch/api/v1/get/datasets?limit=10&l=gn:'+str(g.geonames_id)+'&q='+keyword) response = r.json() if len(response['hits']['hits'])==0: response_bot = 'Sorry, it looks like we don\'t have that! Try to enter other keywords.' else: if len(response['hits']['hits'])>5: therange = 5 else: therange = len(response['hits']['hits']) for i in range(therange): name = response['hits']['hits'][i]['_source']['dataset']['dataset_name'] names.append(name) link = response['hits']['hits'][i]['_source']['dataset']['dataset_link'] links.append(link) for i, e in zip(names,links): table.append([i,e]) response_bot = "Datasets with the keyword {} and within {}".format(keyword, location) + " " + tabulate(table, headers=['Name', 'Link']) elif keyword !='null': r = requests.get('https://search.communidata.at/odgraphsearch/api/v1/get/datasets?limit=10&q='+keyword) response = r.json() if len(response['hits']['hits'])==0: response_bot = 'Sorry, it looks like we don\'t have that! Try to enter other keywords.' else: if len(response['hits']['hits'])>5: therange = 5 else: therange = len(response['hits']['hits']) for i in range(therange): name = response['hits']['hits'][i]['_source']['dataset']['dataset_name'] names.append(name) link = response['hits']['hits'][i]['_source']['dataset']['dataset_link'] links.append(link) for i, e in zip(names,links): table.append([i,e]) response_bot = "Datasets with the keyword {}".format(keyword) + " " + tabulate(table, headers=['Name', 'Link']) elif location !='null' : r = requests.get('https://search.communidata.at/odgraphsearch/api/v1/get/datasets?limit=10&l=gn:'+str(g.geonames_id)) response = r.json() if len(response['hits']['hits'])==0: response_bot = 'Sorry, it looks like we don\'t have that! Try to enter other keywords.' else: if len(response['hits']['hits'])>5: therange = 5 else: therange = len(response['hits']['hits']) for i in range(therange): name = response['hits']['hits'][i]['_source']['dataset']['dataset_name'] names.append(name) link = response['hits']['hits'][i]['_source']['dataset']['dataset_link'] links.append(link) for i, e in zip(names,links): table.append([i,e]) response_bot = "Datasets within {}".format(location) +" "+ tabulate(table, headers=['Name', 'Link']) else: response_bot = 'Sorry, I don\'t understand you! .' dispatcher.utter_message(response_bot) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = "120313 is the infra cost in November 2019" dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): app = tracker.get_slot('app') response = " The app is deployed in Asia" dispatcher.utter_message(response) return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): return [AllSlotsReset()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_message( "Im resetting our dialogue. Go ahead and start a new one :)") return [AllSlotsReset()]