-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcoupang_commission.py
More file actions
52 lines (41 loc) · 1.8 KB
/
coupang_commission.py
File metadata and controls
52 lines (41 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import hmac
import hashlib
import requests
import json
from time import gmtime, strftime
import smssend
from datetime import date, timedelta
yesterday = date.today() - timedelta(1)
DATE = yesterday.strftime('%Y%m%d')
REQUEST_METHOD = "GET"
DOMAIN = "https://api-gateway.coupang.com"
URL = "/v2/providers/affiliate_open_api/apis/openapi/v1/reports/commission?startDate="+DATE+"&endDate="+DATE+"&page=0"
# Replace with your own ACCESS_KEY and SECRET_KEY
ACCESS_KEY = ""
SECRET_KEY = ""
def generateHmac(method, url, secretKey, accessKey):
path, *query = url.split("?")
datetimeGMT = strftime('%y%m%d', gmtime()) + 'T' + strftime('%H%M%S', gmtime()) + 'Z'
message = datetimeGMT + method + path + (query[0] if query else "")
signature = hmac.new(bytes(secretKey, "utf-8"),
message.encode("utf-8"),
hashlib.sha256).hexdigest()
return "CEA algorithm=HmacSHA256, access-key={}, signed-date={}, signature={}".format(accessKey, datetimeGMT, signature)
authorization = generateHmac(REQUEST_METHOD, URL, SECRET_KEY, ACCESS_KEY)
url = "{}{}".format(DOMAIN, URL)
response = requests.request(method=REQUEST_METHOD, url=url,
headers={
"Authorization": authorization,
"Content-Type": "application/json"
},
)
data = response.json()
for row in data['data']:
uid = ""
upw = ""
subject = "쿠팡파트너스"
content = "쿠팡파트너스 \n날짜: {} \n커미션: {}원".format(row['date'], row['commission'])
hpno = ""
callback = ""
jphone = smssend.JmunjaPhone(uid, upw)
presult = jphone.send(subject, content, hpno)