def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) lang = intents["lang"] song = "" # extract artis and music track artist = getSlotbyName("artist", intents) track = getSlotbyName("track", intents) if (artist): song += artist if (track): song += track # if either artist nor music track got found return False if (artist == None and track == None): return False song = geturl(song) # if only artist is given return False to ask fallback if (song == None): return False return generate_answer(), song
def beginn(data, intents): #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) intention = intents["intent"]["intentName"] answer_type = "answer" if(intention == "choice"): slots = ["0"] for xy in range(1): # get slots with ID's from zero to five for x in range(6): slot = getSlotbyName("slot" + str(x),intents) if(slot != None): slots.append(slot) # more than one slot could get extracted if(len(slots) > 1): choice = random.choice(slots) # choose random element untils it is not the first one while(choice == "0"): choice = random.choice(slots) return choice,"https://a-ware.io/wp-content/uploads/2020/02/LOGO.png" else: return False if(intention == "randomint"): # extract range numbers num1 = getSlotbyName("number1",intents) num2 = getSlotbyName("number2",intents) # if first number is not given, set to zero if(num1 == None): num1 = 0 # second number is not given, set to ten if(num2 == None): num2 = 10 # check if first number is bigger than seconds if(num1 >= num2): return random.randint(num2,num1),"https://a-ware.io/wp-content/uploads/2020/02/LOGO.png",answer_type,False # check if first number is smaller than seconds if(num1 <= num2): return random.randint(num1,num2),"https://a-ware.io/wp-content/uploads/2020/02/LOGO.png",answer_type,False # return random number between one and six as it is a real dice if(intention == "diceroll"): return random.randint(1,6),"https://a-ware.io/wp-content/uploads/2020/02/LOGO.png",answer_type,False # return head or number as it is on coin if(intention == "coinflip"): return random.choice(["kopf","zahl","zahl","kopf"]),"https://a-ware.io/wp-content/uploads/2020/02/LOGO.png"
def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) question = intents["input"] lang = intents["lang"] intention = intents["intent"]["intentName"] time = getSlotbyName("time", intents) answer_type = "answer" print(time) if (intention == "alarm"): # extract datetime time = getSlotbyName("time", intents) if (time == None): return "Ich habe die Zeit leider nicht verstanden", "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png" time = time.split(" ") time = time[1] time = time.split(":") intents["hours"] = time[0] intents["minutes"] = time[1] intents["seconds"] = time[2] else: # extract hours, minutes and seconds individually hours = getSlotbyName("time", intents, "hours") minutes = getSlotbyName("time", intents, "minutes") seconds = getSlotbyName("time", intents, "seconds") if (hours == None and minutes == None and seconds == None): return "Ich habe die Zeit leider nicht verstanden", "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png" if (hours == None): intents["hours"] = 0 else: intents["hours"] = hours if (minutes == None): intents["minutes"] = 0 else: intents["minutes"] = minutes if (seconds == None): intents["seconds"] = 0 else: intents["seconds"] = seconds # return answer, url, answer type, set translator to true and change intents to adapted json return generate_answer( intention ), "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png", answer_type, True, intents
def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) question = intents["input"] lang = intents["lang"] answer = "" # extract name and quantity appnames = getSlotbyName("appnames", intents) quantity = getSlotbyName("quantity", intents) if (appnames == None): return False # remove last characters to solve bug with search, bitcoin's --> bitcoin appnames = appnames[:-2] try: # search for names with urllib.request.urlopen( "https://financialmodelingprep.com/api/v3/search?query=" + urllib.parse.quote(appnames) + "&limit=5=") as url: datas = json.loads(url.read().decode()) # get price for each name for x in datas: with urllib.request.urlopen( "https://financialmodelingprep.com/api/v3/quote/" + x["symbol"]) as url2: datas2 = json.loads(url2.read().decode()) prices = datas2[0]["price"] if (quantity != None): prices = prices * float(quantity) prices = str(prices) # format prices, for text to speech price1 = prices.split(".")[0] price2 = prices.split(".")[1] price2 = price2[0] + price2[1] prices = price1 + "." + price2 # append to answer answer += x["name"] + ": " + prices + " $\n\n" except Exception as e: print(e) return False # return if correct answer is generated if (answer != ""): return answer else: return False
def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) lang = intents["lang"] intention = intents["intent"]["intentName"] target = getSlotbyName("target",intents) answer_type = "answer" # try to get target address if(target == None): try: target = datas["get_adress"] intents["target"] = hours answer_type = "answer_requested" except: pass if(intention == "search"): # ask user whats the target he meaned if(target == None): return "Welchen Ort meinen sie ?","https://a-ware.io/wp-content/uploads/2020/02/LOGO.png","get_adress",True,intents # return extracted data without statement return " ","https://a-ware.io/wp-content/uploads/2020/02/LOGO.png",answer_type,False,intents
def beginn(data, intents): global lang results = None #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) name = getSlotbyName("name", intents) if (name == None): return False lang = intents["lang"] # set lang for wikipedia wiki_wiki = wikipediaapi.Wikipedia(lang) wikipedia.set_lang(lang) page_py = wiki_wiki.page(name) # try to generate answer from wikipedia try: return wikipedia.summary(name, sentences=4).split("\n\n")[0] except: pass # use seconds wikipedia library if first one is not working if (page_py.exists()): sentences = page_py.summary[0:-1].split(". ") answer = "" for x in range(3): try: answer += sentences[x] + ". " except: pass return (answer.split("\n\n")[0]) # try to search on english wikipedia for an answer try: wikipedia.set_lang("en") return wikipedia.summary(name, sentences=4).split("\n\n")[0] except: pass # use seconds wikipedia library if first one is not working if (page_py.exists()): wiki_wiki = wikipediaapi.Wikipedia('en') page_py = wiki_wiki.page(name) sentences = page_py.summary[0:-1].split(". ") answer = "" for x in range(3): try: answer += sentences[x] + ". " except: pass return (answer.split("\n\n")[0]) else: return False return False
def beginn(data, intents): data = json.loads(data) intents = json.loads(intents) url = data["calendar_url"] username = data["calendar_username"] password = data["calendar_password"] begin = None event = None intention = intents["intent"]["intentName"] if (intention == "getevents"): try: begin = getSlotbyName("datetime", intents) except Exception as e: print(e) return str( getCalDavEvents(url=url, username=username, password=password, begin=begin) ), "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png" else: begin = getSlotbyName("datetime", intents) event = getSlotbyName("hobbys", intents) if (begin == None): return (False) if (event == None): return str( setCalDavEvents(url=url, username=username, password=password, begin=begin) ), "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png" else: return str( setCalDavEvents(url=url, username=username, password=password, begin=begin, event=event) ), "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png"
def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) lang = intents["lang"] # extract name to call appnames = getSlotbyName("name",intents) # return False if no name to call was found if(appnames == None): return False return generate_answer(appnames),"https://a-ware.io/wp-content/uploads/2020/02/LOGO.png"
def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) question = intents["input"] lang = intents["lang"] # extract object to search images for things = getSlotbyName("things",intents) if(things == None): return generate_answer() # return link to qwant images return generate_answer(),"https://www.qwant.com/?q=" + urllib.parse.quote(things) + "&t=images"
def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) # get language lang = intents["lang"] # get app name appnames = getSlotbyName("appnames", intents) # return False if appname could not get extracted if (appnames == None): return False return generate_answer( appnames), "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png"
def beginn(data, intents): #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) # extract name name = getSlotbyName("name", intents) # if name was not found return False if (name == None): return False # generate question for wolframalpha question = "how old is " + name # ask wolframalpha answer = wolfram_Alpha(question, data) # return False if wolframalpha found no answer if (answer == False): return False else: return answer
def beginn(data, intents): #load users data into json data = json.loads(data) apiKey = data["newsapi"] #load nlu data into json intents = json.loads(intents) #get intention name intention = intents["intent"]["intentName"] lang = intents["lang"] try: lang = data["country"] except: pass thema = getSlotbyName("thema", intents) # return all actuall news if (intention == "allnews"): with urllib.request.urlopen( "https://newsapi.org/v2/top-headlines?country=" + str(lang) + "&apiKey=" + apiKey) as url: datas = json.loads(url.read().decode()) articles = datas["articles"] answer = "" limit = 0 for x in articles: # only return five articles if (limit < 5): answer += x["description"] + "\n\n" limit = limit + 1 # if articles got added successful, return those if (answer != ""): return answer else: return False # return news for specific topic elif (thema != None): with urllib.request.urlopen("https://newsapi.org/v2/everything?q=" + str(thema) + "&language=" + str(lang) + "&apiKey=" + apiKey) as url: datas = json.loads(url.read().decode()) articles = datas["articles"] answer = "" limit = 0 for x in articles: # only return five articles if (limit < 5): answer += x["description"] + "\n\n" limit = limit + 1 # if articles got added successful, return those if (answer != ""): return answer else: return False #at least one return (no in, if or try) statement has to be not indented #this statement is not executed. Necessary for python interpreter tho. return False
def beginn(data, intents): global lang #load users data into json datas = json.loads(data) #load nlu data into json intents = json.loads(intents) lang = intents["lang"] intention = intents["intent"]["intentName"] numbered = getSlotbyName("numbered", intents) president = getSlotbyName("president", intents) answer_type = "answer" answer = "" # download and read data of american presidents col_list = ["Number", "Name", "Time"] url = "https://raw.githubusercontent.com/flozi00/AWare-Skill-Server/master/skillserver/data/uspresidents.csv" s = requests.get(url).content df = pd.read_csv(io.StringIO(s.decode('utf-8')), usecols=col_list) # check if user want to search by number or name if (intention == "presnumber"): # if ordinal not found, try with number if (numbered == None): numbered = getSlotbyName("number", intents) # if no number found, return false if (numbered == None): return False # iterate over dataset to find the right entrie for index, row in df.iterrows(): if (int(row["Number"]) == int(numbered)): answer = answer + row["Name"] + "\n" if (intention == "whichpres"): if (president == None): return False # split name into single names president = president.split(" ") for index, row in df.iterrows(): contains = True # check if alle single names are in entrie for name in president: if (name.lower() in row["Name"].lower()): contains = True else: contains = False # add entrie to answer if (contains): answer = answer + row["Name"] + ": " + str( row["Number"]) + "\n" if (answer != "" and answer != None): """answer = text you want to speak out, second is the url to load in browser, third is answer type ( you need to define if you want to have dialogs), fourth is boolean if you want to use translator before output or not (this case we dont need translator because only return name or number)""" return answer, "https://a-ware.io/wp-content/uploads/2020/02/LOGO.png", answer_type, False else: # return false, cause no answer found by skill return False