in processors/recommendations.py [0:0]
def get_insights(self, client, insight_types, parents, all_locations,
filter):
"""Fetches insights with specified insight types from applicable locations"""
insights = {}
for parent in parents:
insights[parent[0]] = []
for location in all_locations:
for insight_type in insight_types:
ok_parent = False
for test in self.insights[insight_type]['parent']:
if test(parent[0]):
ok_parent = True
break
if not ok_parent:
continue
ok_location = False
for test in self.insights[insight_type]['location']:
if test(location):
ok_location = True
break
if not ok_location:
continue
full_parent = '%s/locations/%s/insightTypes/%s' % (
parent[0], location, insight_type)
self.logger.debug('Fetching insights...',
extra={
'type': parent[0].split('/')[0],
'parent': full_parent,
'location': location,
'insight_type': insight_type
})
insights_request = ListInsightsRequest(parent=full_parent,
filter=filter)
insights_response = client.list_insights(
request=insights_request)
for insight in insights_response:
_insight = {
'type': parent[0].split('/')[0],
'parent': parent[1],
'link': self.get_link(parent),
'location': location,
'insight_type': insight_type,
'insight': Insight.to_dict(insight),
}
insights[parent[0]].append(_insight)
return insights