in processors/recommendations.py [0:0]
def get_recommendations(self, client, recommender_types, parents,
all_locations, filter):
"""Fetches recommendations with specified recommender types from applicable locations"""
recommendations = {}
for parent in parents:
recommendations[parent[0]] = []
for location in all_locations:
for recommender_type in recommender_types:
ok_parent = False
for test in self.recommenders[recommender_type]['parent']:
if test(parent[0]):
ok_parent = True
break
if not ok_parent:
continue
ok_location = False
for test in self.recommenders[recommender_type]['location']:
if test(location):
ok_location = True
break
if not ok_location:
continue
full_parent = '%s/locations/%s/recommenders/%s' % (
parent[0], location, recommender_type)
self.logger.debug('Fetching recommendations...',
extra={
'type': parent[0].split('/')[0],
'parent': full_parent,
'location': location,
'recommender': recommender_type
})
rec_response = client.list_recommendations(
parent=full_parent, filter=filter)
for recommendation in rec_response:
_rec = {
'type':
parent[0].split('/')[0],
'parent':
parent[1],
'link':
self.get_link(parent),
'location':
location,
'recommender_type':
recommender_type,
'recommendation':
Recommendation.to_dict(recommendation),
}
recommendations[parent[0]].append(_rec)
return recommendations