Spaces:
Sleeping
Sleeping
Delete tokopedia.py
Browse files- tokopedia.py +0 -127
tokopedia.py
DELETED
@@ -1,127 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
|
3 |
-
def request_product_id(shop_domain, product_key):
|
4 |
-
endpoint = "https://gql.tokopedia.com/graphql/PDPGetLayoutQuery"
|
5 |
-
payload = {
|
6 |
-
"operationName": "PDPGetLayoutQuery",
|
7 |
-
"variables": {
|
8 |
-
"shopDomain": f"{shop_domain}",
|
9 |
-
"productKey": f"{product_key}",
|
10 |
-
"apiVersion": 1,
|
11 |
-
},
|
12 |
-
"query": """fragment ProductVariant on pdpDataProductVariant {
|
13 |
-
errorCode
|
14 |
-
parentID
|
15 |
-
defaultChild
|
16 |
-
children {
|
17 |
-
productID
|
18 |
-
}
|
19 |
-
__typename
|
20 |
-
}
|
21 |
-
|
22 |
-
query PDPGetLayoutQuery($shopDomain: String, $productKey: String, $layoutID: String, $apiVersion: Float, $userLocation: pdpUserLocation, $extParam: String, $tokonow: pdpTokoNow, $deviceID: String) {
|
23 |
-
pdpGetLayout(shopDomain: $shopDomain, productKey: $productKey, layoutID: $layoutID, apiVersion: $apiVersion, userLocation: $userLocation, extParam: $extParam, tokonow: $tokonow, deviceID: $deviceID) {
|
24 |
-
requestID
|
25 |
-
name
|
26 |
-
pdpSession
|
27 |
-
basicInfo {
|
28 |
-
id: productID
|
29 |
-
}
|
30 |
-
components {
|
31 |
-
name
|
32 |
-
type
|
33 |
-
position
|
34 |
-
data {
|
35 |
-
...ProductVariant
|
36 |
-
__typename
|
37 |
-
}
|
38 |
-
__typename
|
39 |
-
}
|
40 |
-
__typename
|
41 |
-
}
|
42 |
-
}
|
43 |
-
""",
|
44 |
-
}
|
45 |
-
|
46 |
-
headers = {
|
47 |
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
|
48 |
-
"Referer": "https://www.tokopedia.com",
|
49 |
-
"X-TKPD-AKAMAI": "pdpGetLayout",
|
50 |
-
}
|
51 |
-
|
52 |
-
return requests.request(method="POST", url=endpoint, json=payload, headers=headers, timeout=30)
|
53 |
-
|
54 |
-
|
55 |
-
def request_product_review(product_id, page=1, limit=20):
|
56 |
-
ENDPOINT = "https://gql.tokopedia.com/graphql/productReviewList"
|
57 |
-
payload = {
|
58 |
-
"operationName": "productReviewList",
|
59 |
-
"variables": {
|
60 |
-
"productID": f"{product_id}",
|
61 |
-
"page": page,
|
62 |
-
"limit": limit,
|
63 |
-
"sortBy": "",
|
64 |
-
"filterBy": "",
|
65 |
-
},
|
66 |
-
"query": """query productReviewList($productID: String!, $page: Int!, $limit: Int!, $sortBy: String, $filterBy: String) {
|
67 |
-
productrevGetProductReviewList(productID: $productID, page: $page, limit: $limit, sortBy: $sortBy, filterBy: $filterBy) {
|
68 |
-
productID
|
69 |
-
list {
|
70 |
-
id: feedbackID
|
71 |
-
variantName
|
72 |
-
message
|
73 |
-
productRating
|
74 |
-
reviewCreateTime
|
75 |
-
reviewCreateTimestamp
|
76 |
-
isReportable
|
77 |
-
isAnonymous
|
78 |
-
reviewResponse {
|
79 |
-
message
|
80 |
-
createTime
|
81 |
-
__typename
|
82 |
-
}
|
83 |
-
user {
|
84 |
-
userID
|
85 |
-
fullName
|
86 |
-
image
|
87 |
-
url
|
88 |
-
__typename
|
89 |
-
}
|
90 |
-
likeDislike {
|
91 |
-
totalLike
|
92 |
-
likeStatus
|
93 |
-
__typename
|
94 |
-
}
|
95 |
-
stats {
|
96 |
-
key
|
97 |
-
formatted
|
98 |
-
count
|
99 |
-
__typename
|
100 |
-
}
|
101 |
-
badRatingReasonFmt
|
102 |
-
__typename
|
103 |
-
}
|
104 |
-
shop {
|
105 |
-
shopID
|
106 |
-
name
|
107 |
-
url
|
108 |
-
image
|
109 |
-
__typename
|
110 |
-
}
|
111 |
-
hasNext
|
112 |
-
totalReviews
|
113 |
-
__typename
|
114 |
-
}
|
115 |
-
}
|
116 |
-
""",
|
117 |
-
}
|
118 |
-
|
119 |
-
headers = {
|
120 |
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
|
121 |
-
"Referer": "https://www.tokopedia.com",
|
122 |
-
"X-TKPD-AKAMAI": "productReviewList",
|
123 |
-
}
|
124 |
-
|
125 |
-
return requests.request(
|
126 |
-
method="POST", url=ENDPOINT, json=payload, headers=headers, timeout=30
|
127 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|