现在,我有一种非常昂贵(API 密集型)的方式来获取每个客户的访问历史记录。首先,我获取每个客户 ID,然后调用 GetClientVisits 来获取每个客户的历史记录。有没有一种 API 强度较低的方法来做到这一点?
请参见下面的代码:
clientService = ClientServiceCalls()
clientResponse = clientService.GetClientsByString(self.USER_NAME, self.USER_PASSWORD, self.SITE_IDS, '')
clientList = clientResponse.Clients.Client
clientVisitsDict = []
for c in clientList:
clientResponseVisits = clientService.GetClientVisits(self.USER_NAME, self.USER_PASSWORD, self.SITE_IDS, str(c.ID), oneMonthAgo, datetime.today())
if clientResponseVisits.Visits:
visitsList = clientResponseVisits.Visits.Visit
for v in visitsList:
q = {}
q['cust_id'] = str(c.ID)
q['timeframe'] = str(datetime.now().month) + '-' + str(datetime.now().year)
q['profile'] = str(self.PROFILE)
q['cust_name'] = str(c.FirstName) + ' ' + str(c.LastName)
q['class_id'] = str(v.ClassID)
q['class_time'] = str(v.ClassID)
q['class_name'] = str(v.Name)
q['class_location'] = str(v.Location.Name)
q['class_instructor_id'] = str(v.Staff.ID)
q['class_instructor_name'] = str(v.Staff.Name)
print q['class_instructor_name']
clientVisitsDict.append(q)