import requests import json import numpy as np url = 'http://mmx-recsys-ingress.flop.search-infra.etsy-searchinfra-gke-prod-2.etsycloud.com/apiv2/general/rec_set/dynamic/recs' headers = { 'accept': 'application/json', 'Content-Type': 'application/json', } def fn(notificationType, source, trigger, listingId, shopId): data = { "coreParams": { "limit": 200, "modulePlacement": "test" }, "recSetParams": { "candidate": { "name": "notifications-with-features-extractor", "args": { "notifications": [ { "notificationId": "", "notificationType": notificationType, "source": source, "trigger": trigger, "listingIds": [listingId], "shopIds": [shopId], "createdOn": 0, "hasCta": True, "isSeen": True, "tab": "Deals" } ] } }, "ranking": { "ranker": { "name": "notifications-ranker-v1" }, "context": { "name": "user-id-context", "args": { "userId": 78905933 } } } } } return data for notification_type in ['aco', 'ofl', 'psfcl', 'psffl', 'psffs', 'pssfl', 'rfc', 'tyc', 'asfl', 'cr', 'fbis', 'nfyfs']: for trigger in ['coupon', 'in_stock', 'new_listings', 'on_sale', 'only_1_left', 'recommendations']: for source in ['cart_listing', 'collection', 'favorite_listing', 'favorite_shop', 'purchased_shop', 'saved_for_later_listing']: for listingId, shopId in [(1682417764, 26429036), (1733348540, 10993646)]: data = fn(notification_type, source, trigger, listingId, shopId) response = requests.post(url, headers=headers, data=json.dumps(data)) print(f"{notification_type}-{trigger}-{source}-{listingId}-{shopId} -> {np.round(response.json()['recs'][0]['score'], 3)}")