def taapi(request): """ Acting as a proxy between the Tradeoff Analytics widget and service. """ theData= {} theResponse = {"Error":"Request could not be submitted"} theRequest = json.loads(request.body.decode("utf-8")) #with open('dumpedrequestjson.txt', 'w') as outfile: # json.dump(theRequest, outfile) if theRequest: wdc = WDCService('TA') theResponse = wdc.performOperation(theRequest) if 'error' in theResponse: print('Error Detected', theResponse['error']) return HttpResponse(json.dumps(theResponse), content_type="application/json")
def processPIRequest(request, theData): results = {} data = {} errorFound = False wdc = WDCService('PI') service_creds = wdc.getCreds() personality = theData["personality"] performTwitterScan = theData["twitterScan"] if performTwitterScan and personality and 0 < len(personality): # Data needs to come from twitter pulledData = pullTwitterTimeline(personality) if "error" in pulledData: errorFound = True elif "data" in pulledData: data = pulledData["data"] else: data = theData["data"].encode('utf8', 'replace') if not errorFound: results = wdc.performOperation(data) service_creds['results'] = results pi = Pidata(results) keys = pi.big5keys() traits = {} for trait in keys: traits[trait] = pi.getTraitValue(trait, False) service_creds["traits"] = traits savePersonality(personality, pi) results = service_creds else: results["results"] = data return results