-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitc_reviews_requests.py
160 lines (128 loc) · 6.72 KB
/
itc_reviews_requests.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from requests import session
import os
import re
import threading
import json
import sys
class ITCApi:
def __init__(self, account_email, account_password, app_id):
self.app_identifier = app_id
self.setup_session(account_email, account_password)
def setup_session(self, account_email, account_password):
self.session = session()
r = self.session.get('https://appstoreconnect.apple.com/olympus/v1/app/config?hostname=itunesconnect.apple.com')
apple_widget_key = json.loads(r.text)["authServiceKey"]
headers = {
'Content-Type': 'application/json',
'X-Apple-Widget-Key': apple_widget_key,
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/48.0.2564.116 Safari/537.36',
'Accept': 'application/json',
'Referrer': 'https://idmsa.apple.com',
}
payload = {
'accountName': account_email,
'password': account_password,
'rememberMe': False,
}
self.session.post('https://idmsa.apple.com/appleauth/auth/signin', json=payload, headers=headers)
#print(self.session.cookies)
# Requests itunes connect page that will give us itCtx cookie needed for api requests
self.session.get('https://appstoreconnect.apple.com/olympus/v1/session', allow_redirects=False)
#print(self.session.cookies)
if 'myacinfo' not in self.session.cookies.get_dict().keys():
raise Exception('Didn\'t get the myacinfo cookie')
if 'itctx' not in self.session.cookies.get_dict().keys():
raise Exception('Didn\'t obtain the itctx cookie')
# We are connected
self.max_index = self.get_max_reviews_page_index()
def get_max_reviews_page_index(self):
data = self.get_last_reviews()
return int(round(int(data['data']['reviewCount']) / 100))
def get_last_reviews(self):
r = self.session.get('https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/{app_id}'
'/platforms/ios/reviews'.format(app_id=self.app_identifier))
data = json.loads(r.text)
return data
def get_reviews_by_page_index(self, page_index):
if page_index < 1:
raise Exception('Page index must starts from 1, dummy')
if page_index > self.max_index:
raise Exception('Page index is geater than max index')
index = (page_index * 100)
r = self.session.get('https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/{app_id}'
'/platforms/ios/reviews?index={'
'index}&sort=REVIEW_SORT_ORDER_MOST_RECENT'.format(index=index,
app_id=self.app_identifier))
data = json.loads(r.text)
return data
def reply_to_review(self, review_id, reply):
if review_id <= 0:
raise Exception('Review identifier is not correct')
if len(reply) == 0 or reply is None:
raise Exception('Reply must not be empty')
headers = {
'Accept-Encoding': 'gzip, deflate, sdch, br',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive',
'Accept': 'application/json, text/plain, */*',
'Host': 'itunesconnect.apple.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/44.0.2403.157 Safari/537.36 '
}
payload = {
'responseText': reply,
'reviewId': review_id
}
r = self.session.post('https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/{app_id}'
'/platforms/ios/reviews/{review_id}/responses'.format(review_id=review_id,
app_id=self.app_identifier),
json=payload, headers=headers)
data = json.loads(r.text)
if data['statusCode'] == 'SUCCESS':
r = self.session.get(
'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/{app_id}/platforms/ios/reviews?reviewId={review_id}'.format(
review_id=review_id, app_id=self.app_identifier))
data = json.loads(r.text)
return data
return None
def update_reply_to_review(self, review_id, reply_id, updated_reply):
if review_id <= 0:
raise Exception('Review identifier is not correct')
if reply_id <= 0:
raise Exception('Reply identifier is not correct')
if len(updated_reply) == 0 or updated_reply is None:
raise Exception('Reply must not be empty')
headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive',
'Accept': 'application/json, text/plain, */*',
'Host': 'itunesconnect.apple.com',
'Content-Type': 'application/json;charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/44.0.2403.157 Safari/537.36 '
}
payload = {
'responseText': updated_reply
}
r = self.session.put('https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/{app_id}'
'/platforms/ios/reviews/{review_id}/responses/{reply_id}'.format(review_id=review_id,
app_id=self.app_identifier,
reply_id=reply_id),
json=payload, headers=headers)
data = json.loads(r.text)
if data['statusCode'] == 'SUCCESS':
r = self.session.get(
'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/{app_id}/platforms/ios/reviews?reviewId={review_id}'.format(
review_id=review_id, app_id=self.app_identifier))
data = json.loads(r.text)
return data
return None
if __name__ == '__main__':
itc = ITCApi('your_account_email', 'your_account_password', 'your_app_id')
# print(itc.get_last_reviews())
# print(itc.reply_to_review(2070010131, 'Thanks for your using XXXX application!'))
# print(itc.get_reviews_by_page_index(13))
# print(itc.get_max_reviews_page_index())
# print(itc.update_reply_to_review(2070010131, 2262578, 'Thanks for your feedback!'))