def new_message(): data = request.get_json() # check for errors in payload errors = check_payload(data, ["sender", "msg", "timestamp"]) if len(errors) > 0: return {"errors": errors}, 400 # parse message, format args, and check for errors in service and arguments msg = data["msg"] service, arguments, errors = parse_service_and_args_from( msg, services_dict) if len(errors) > 0: return {"errors": errors}, 400 # perform service if service == "help": return {"msg": help()} elif service == "add": return {"msg": add(arguments[0], arguments[1])} elif service == "subtract": return {"msg": subtract(arguments[0], arguments[1])} elif service == "multiply": return {"msg": multiply(arguments[0], arguments[1])} elif service == "divide": return {"msg": divide(arguments[0], arguments[1])} elif service == "search": return {"msg": search(arguments[0])} else: return {"msg": "Sorry, I don't know how to do that."}
def ldap_update(self, commit=True): ldap = services.search(self.user.username) if not ldap == None: if not ldap.get('givenName') is None: self.user.first_name = ldap.get('givenName')[0] if not ldap.get('sn') is None: self.user.last_name = ldap.get('sn')[0] if not ldap.get('homePostalAddress') is None: self.address = ldap.get('homePostalAddress')[0] else: self.address = "" if not ldap.get('postalAddress') is None: self.mailbox = ldap.get('postalAddress')[0] else: self.mailbox = "" if not ldap.get('ou') is None: self.school = ldap.get('ou')[0] if not ldap.get('mail') is None: self.user.email = ldap.get('mail')[0] if commit: self.save() def __str__(self): return self.user.get_full_name() def __unicode__(self): return self.user.get_full_name()
def search_wrapper(): data = request.get_json() errors = check_payload(data, ["query"]) if len(errors) > 0: return {"errors": errors}, 400 query = data['query'] result = search(query) return {"result": result}
def go(): text = 'profiling' results = services.search(text) print('search: {}'.format(results)) records = data_access.get_records(text) print('db: {}'.format(len(records))) total = core_compute.compute_analytics(results, records) print("The total is: {:,}".format(total))
def go(): text = 'profiling' results = services.search(text) print('Talk Python search results:') for r in results: print(r[:100].strip() + '...') records = data_access.get_records(text) print('db: {}'.format(len(records))) total = core_compute.compute_analytics(results, records) print("The total is: {:,}".format(total))
def get(request, query=None): response = services.search('#' + query) return JsonResponse(response.json())