How to use get_wa method in avocado

Best Python code snippet using avocado_python

calc.py

Source:calc.py Github

copy

Full Screen

...153 else:154 #### Attempt #4 (DuckDuckGo's HTML)155 ## This relies on BeautifulSoup; if it can't be found, don't even bother156 #### Attempt #3 (Wolfram Alpha)157 status, answer = get_wa(q)158 if status:159 jenni.say(answer + ' [WA]')160 else:161 ## If we made it this far, we have tried all available resources162 jenni.say('Absolutely no results!')163c.commands = ['c', 'cal', 'calc']164c.example = '.c 5 + 3'165def py(jenni, input):166 """.py <code> -- evaluates python code"""167 code = input.group(2)168 if not code:169 return jenni.reply('No code provided.')170 query = code.encode('utf-8')171 uri = 'https://tumbolia-two.appspot.com/py/'172 try:173 answer = web.get(uri + web.urllib.quote(query))174 if answer is not None and answer != "\n":175 jenni.say(answer)176 else:177 jenni.reply('Sorry, no result.')178 except Exception, e:179 jenni.reply('The server did not return an answer.')180py.commands = ['py', 'python']181py.example = '.py print "Hello world, %s!" % ("James")'182def get_wa(search):183 txt = search184 txt = txt.decode('utf-8')185 txt = txt.encode('utf-8')186 query = txt187 uri = 'https://tumbolia-two.appspot.com/wa/'188 uri += urllib.quote(query.replace('+', '%2B'))189 answer = web.get(uri)190 if answer:191 answer = answer.decode("string_escape")192 answer = HTMLParser.HTMLParser().unescape(answer)193 match = re.search('\\\:([0-9A-Fa-f]{4})', answer)194 if match is not None:195 char_code = match.group(1)196 char = unichr(int(char_code, 16))197 answer = answer.replace('\:' + char_code, char)198 waOutputArray = string.split(answer, ";")199 newOutput = list()200 for each in waOutputArray:201 temp = each.replace('\/', '/')202 newOutput.append(temp)203 waOutputArray = newOutput204 if (len(waOutputArray) < 2):205 return True, answer206 else:207 return True, waOutputArray[0] + ' | ' + ' | '.join(waOutputArray[1:4])208 waOutputArray = list()209 else:210 return False, str()211def wa(jenni, input):212 """.wa <input> -- queries WolframAlpha with the given input."""213 if not input.group(2):214 return jenni.reply("No search term.")215 txt = input.group(2)216 txt = txt.encode('utf-8')217 txt = txt.decode('utf-8')218 txt = txt.encode('utf-8')219 status, answer = get_wa(txt)220 if status:221 jenni.say(answer)222 else:223 jenni.say('Sorry, no result from WolframAlpha.')224wa.commands = ['wa', 'wolfram']225wa.example = '.wa land area of the European Union'226if __name__ == '__main__':...

Full Screen

Full Screen

wao.py

Source:wao.py Github

copy

Full Screen

...3from django.db import transaction4from api.models import (Classifier, Project, CredentialWA,5 Label, Data, Pool, PredictProba)6from main.celery import async_wao_update7def get_wa(project_id, version='2018-09-20'):8 """9 Gets WA object from IBM lib10 """11 url, api_key = get_credentials(project_id)12 wa = AssistantV1(13 version=version,14 iam_apikey=api_key,15 url=url16 )17 return wa18def get_credentials(project_id):19 credentials = CredentialWA.objects.get(project__id=project_id)20 url = credentials.url21 api_key = credentials.api_key22 return (url, api_key)23def update(body, project_id):24 ''' wrapper necessary for testing '''25 async_wao_update.delay(body, project_id)26def get_logs(project_id, is_first=False, is_accuracy=False):27 """update logs based on last log date"""28 clf = Classifier.objects.get(29 project__id=project_id, is_accuracy=is_accuracy)30 project = Project.objects.get(id=project_id)31 response = {}32 if is_first:33 response = get_wa(project_id).list_logs(34 workspace_id=clf.ibm_classifier_id,35 sort='request_timestamp',36 ).get_result()37 else:38 query_filter = "response_timestamp>" + clf.log_date39 response = get_wa(project_id).list_logs(40 workspace_id=clf.ibm_classifier_id,41 sort='request_timestamp',42 filter=query_filter43 ).get_result()44 with transaction.atomic():45 if response["logs"]:46 for log in response["logs"]:47 new_data = Data(48 project=project,49 content=log["request"]["input"]["text"]50 )51 new_data.save()52 new_pool = Pool(data=new_data)53 new_pool.save()54 label = Label.objects.get(55 project__id=project_id,56 label=log["response"]["intents"][0]["intent"]57 )58 new_proba = PredictProba(59 label=label,60 pool=new_pool,61 proba=log["response"]["intents"][0]["confidence"]62 )63 new_proba.save()64 last_log_time = response["logs"][-1]["response_timestamp"]65 clf.log_date = last_log_time66 clf.save()67def get_intents(project_id, is_accuracy=False):68 """populate labels with assistant intents"""69 clf = Classifier.objects.get(70 project__id=project_id, is_accuracy=is_accuracy)71 project = Project.objects.get(id=project_id)72 response = get_wa(project_id).list_intents(73 workspace_id=clf.ibm_classifier_id74 ).get_result()75 with transaction.atomic():76 for intent in response["intents"]:77 new_label = Label(label=intent["intent"], project=project)78 new_label.save()79def update_intent(pool_id, label_id, project_id, label, is_accuracy=False):80 """creates an example on an intent based on the rotulated log"""81 clf = Classifier.objects.get(82 project__id=project_id, is_accuracy=is_accuracy)83 get_wa(project_id).create_intent(84 workspace_id=clf.ibm_classifier_id,85 intent=label,86 examples=[87 {'text': Data.objects.get(id=pool_id).content}88 ]89 )90 try:91 response = get_wa(project_id).create_example(92 workspace_id=clf.ibm_classifier_id,93 intent=Label.objects.get(id=label_id).label,94 text=Data.objects.get(id=pool_id).content95 )96 except Exception as e:97 """98 Tries to upload new example to intent, but it might exist already.99 """100 pass...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful