본문 바로가기

쿠팡파트너스 파이썬 코드

kcyland 2025. 6. 19.
반응형



쿠팡에서 특정 제품을 검색했을때 나오는 목록들을 쿠팡파트너스 api 이용해서 블로그 포스팅에 활용하고 싶어 api코드는 내가 넣을테니 파이썬으로 코딩후에 .py 파일로 만들어줘



import time import hmac import hashlib import base64 import requests

ACCESS_KEY = '여기에_당신의_ACCESS_KEY' SECRET_KEY = '여기에_당신의_SECRET_KEY' DOMAIN = 'https://api-gateway.coupang.com'

def make_headers(method, url_path): timestamp = str(int(time.time() * 1000)) message = method + ' ' + url_path + '\n' + timestamp + '\n' + ACCESS_KEY signature = base64.b64encode( hmac.new(SECRET_KEY.encode('utf-8'), message.encode('utf-8'), hashlib.sha256).digest() ) return { 'Authorization': f'CEA {ACCESS_KEY}:{signature.decode()}', 'Content-Type': 'application/json;charset=UTF-8', 'X-Requested-Timestamp': timestamp }

def search_products(keyword, limit=5): url_path = '/v2/providers/affiliate_open_api/apis/openapi/v1/products/search' query = f"?keyword={keyword}&limit={limit}&subId=blog01" headers = make_headers("GET", url_path) response = requests.get(DOMAIN + url_path + query, headers=headers) return response.json()['data']

def generate_blog_html(products): html = '<div style="font-family:Arial, sans-serif;">' html += '<h2>\ud83d\udcc8 \uc624\ub298\uc758 \ucd94\ucc9c \uc0c1\ud488</h2>' for item in products: html += f''' <div style="border:1px solid #ddd; padding:10px; margin-bottom:10px; border-radius:10px;"> <h3 style="margin:0;"><a href="{item['productUrl']}" target="_blank" style="text-decoration:none; color:#333;">{item['productName']}</a></h3> <p>\ud83d\udcb0 <strong>\uac00\uaca9:</strong> {item['productPrice']}\uc6d0</p> <p>\ud83c\udff7




반응형

댓글