Created
February 3, 2020 16:07
-
-
Save gcsfred/67802af8e2832fd84da571a029a06c02 to your computer and use it in GitHub Desktop.
Retrieve product ranking from Amazon (fragment)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_product_ranking(config, user, input_list): | |
_log_info('Retrieving product ranking') | |
answer = _get_ranking(config['DEFAULT']['product_rankings_campaignArn'], user, input_list, | |
float(config['DEFAULT']['product_ranking_start']), | |
float(config['DEFAULT']['product_ranking_steps_down'])) | |
return answer | |
def _get_ranking(campaign, user, input_list, start, steps_down): | |
personalize = boto3.client('personalize-runtime', 'us-east-2') | |
response = personalize.get_personalized_ranking(campaignArn=campaign, userId=user, inputList=input_list) | |
answer = {} | |
i = 0 | |
_log_info('Ranked items:') | |
for item in response['personalizedRanking']: | |
k = start - (i*steps_down) | |
answer[item['itemId']] = k | |
_log_info('Ranking ' + item['itemId'] + ' to ' + str(k)) | |
i = i+1 | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment