forked from NoMore201/googleplay-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
124 lines (93 loc) · 3.23 KB
/
test.py
File metadata and controls
124 lines (93 loc) · 3.23 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
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
from gpapi.googleplay import GooglePlayAPI, RequestError
import sys
import argparse
ap = argparse.ArgumentParser(description='Test download of expansion files')
ap.add_argument('-e', '--email', dest='email', help='google username')
ap.add_argument('-p', '--password', dest='password', help='google password')
args = ap.parse_args()
server = GooglePlayAPI('it_IT', 'Europe/Rome')
# LOGIN
print('\nLogging in with email and password\n')
server.login(args.email, args.password, None, None)
gsfId = server.gsfId
authSubToken = server.authSubToken
print('\nNow trying secondary login with ac2dm token and gsfId saved\n')
server = GooglePlayAPI('it_IT', 'Europe/Rome')
server.login(None, None, gsfId, authSubToken)
# SEARCH
apps = server.search('telegram', 34, None)
print('\nSearch suggestion for "fir"\n')
print(server.searchSuggest('fir'))
print('nb_result: 34')
print('number of results: %d' % len(apps))
print('\nFound those apps:\n')
for a in apps:
print(a['docId'])
# HOME APPS
print('\nFetching apps from play store home\n')
home = server.getHomeApps()
for cat in home:
print("cat {0} with {1} apps".format(cat.get('categoryId'),
str(len(cat.get('apps')))))
# DOWNLOAD
docid = apps[0]['docId']
print('\nTelegram docid is: %s\n' % docid)
print('\nAttempting to download %s\n' % docid)
fl = server.download(docid)
with open(docid + '.apk', 'wb') as apk_file:
for chunk in fl.get('file').get('data'):
apk_file.write(chunk)
print('\nDownload successful\n')
# DOWNLOAD APP NOT PURCHASED
# Attempting to download Nova Launcher Prime
# it should throw an error 'App Not Purchased'
print('\nAttempting to download "com.teslacoilsw.launcher.prime"\n')
errorThrown = False
try:
app = server.search('nova launcher prime', 3, None)
app = filter(lambda x: x['docId'] == 'com.teslacoilsw.launcher.prime', app)
app = list(app)[0]
fl = server.delivery(app['docId'], app['versionCode'])
except RequestError as e:
errorThrown = True
print(e)
if not errorThrown:
print('Download of previous app should have failed')
sys.exit(1)
# BULK DETAILS
testApps = ['org.mozilla.focus', 'com.non.existing.app']
bulk = server.bulkDetails(testApps)
print('\nTesting behaviour for non-existing apps\n')
if bulk[1] is not None:
print('bulkDetails should return None for non-existing apps')
sys.exit(1)
print('\nResult from bulkDetails for %s\n' % testApps[0])
print(bulk[0])
# DETAILS
print('\nGetting details for %s\n' % testApps[0])
details = server.details(testApps[0])
print(details)
# REVIEWS
print('\nGetting reviews for %s\n' % testApps[0])
revs = server.reviews(testApps[0])
for r in revs:
print(r['comment'])
# BROWSE
print('\nBrowse play store categories\n')
browse = server.browse()
for b in browse:
print(b['name'])
print('\nBrowsing the %s category\n' % browse[0]['catId'])
browseCat = server.browse(browse[0]['catId'])
for b in browseCat:
print('%s subcategory with %d apps' % (b['title'], len(b['apps'])))
# LIST
cat = 'MUSIC_AND_AUDIO'
print('\nList %s subcategories\n' % cat)
catList = server.list(cat)
for c in catList:
print(c)
print('\nList %s apps for %s category\n' % (catList[0], cat))
appList = server.list(cat, catList[0])
for app in appList:
print(app['docId'])