-
Notifications
You must be signed in to change notification settings - Fork 0
/
spynot.py
executable file
·135 lines (112 loc) · 4.88 KB
/
spynot.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
#!/usr/bin/python
# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None
from config import *
from googleplay import GooglePlayAPI
import json as libjson
def GetDetails(packageName):
api = GooglePlayAPI(ANDROID_ID)
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
try:
message = api.toDict(api.details(packageName))
except:
print "Error: something went wrong."
return
if "docV2" not in message:
return dict(method="GetDetails", id=1, searchString=packageName, GooglePlayData=None, response="ok")
app = message['docV2']
permissions = []
if "permission" in app["details"]["appDetails"]:
for i in range(len(app['details']['appDetails']['permission'])): permissions.append(app['details']['appDetails']['permission'][i])
appData = dict(
title=app['title'],
author=app['creator'],
description=app['descriptionHtml'],
cost=app['offer'][0]['formattedAmount'],
icon=app['image'][0]['imageUrl'],
category=str(app['details']['appDetails']['appCategory'][0]),
permissions=permissions,
#numDownloads=app['details']['appDetails']['numDownloads'],
playRating="%.2f" % app['aggregateRating']['starRating'],
url=app['shareUrl'],
packageName=app['docid'] )
if 'numDownloads' in app['details']['appDetails']:
appData['numDownloads'] = app['details']['appDetails']['numDownloads']
else:
appData['numDownloads'] = "~0"
return dict(method="GetDetails", id=1, searchString=packageName, GooglePlayData=appData, response="ok")
def GetAppPermissionsByCategory(category, subcategory, numResults=20):
api = GooglePlayAPI(ANDROID_ID)
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
subcategory = subcategory.lower()
if subcategory == "paid":
subcategory = "apps_topselling_paid"
else:
subcategory = "apps_topselling_free"
try:
message = api.toDict(api.list(category, subcategory, str(numResults), None))
except:
print "Error: something went wrong."
return
if "doc" not in message:
return dict(method="GetAppPermissionsByCategory", id=1, category=category, subcategory=subcategory, results=None, response="ok")
doc = message["doc"][0]
appList = []
for c in doc["child"]:
appList.append(c["docid"])
try:
message = api.toDict(api.bulkDetails(appList))
except:
print "Error: something went wrong."
return
appList = []
for i in range(len(message["entry"])):
app = message["entry"][i]["doc"]
permissions = []
if "permission" in app["details"]["appDetails"]:
for i in range(len(app['details']['appDetails']['permission'])): permissions.append(app['details']['appDetails']['permission'][i])
appList.append(dict(packageName=app["docid"], permissions=permissions))
return dict(method="GetAppPermissionsByCategory", id=1, category=category, subcategory=subcategory, results=appList, response="ok")
def SearchApp(searchString):
api = GooglePlayAPI(ANDROID_ID)
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
try:
message = api.toDict(api.search(searchString, None, None))
except:
print "Error: something went wrong. Maybe the nb_res you specified was too big?"
return
if "doc" not in message:
return dict(method="SearchApp", id=1, searchString=searchString, results=None, response="ok")
doc = message["doc"][0]
appList = []
for c in doc["child"]:
if "badgeForCreator" in c["annotations"]:
badge = True
else:
badge = False
appList.append(dict(title=c["title"], author=c["creator"], superDeveloper=badge, playRating="%.2f" % c["aggregateRating"]["starRating"], icon=c["image"][0]["imageUrl"], packageName=c["docid"]))
return dict(method="SearchApp", id=1, searchString=searchString, results=appList, response="ok")
def api(json=None):
if json is None or json == "":
return libjson.dumps(dict(method="NoJSON", id=None, response="bad"), indent=2)
json = libjson.loads(json)
if json["method"] == "GetDetails":
if "searchString" in json:
return libjson.dumps(GetDetails(json["searchString"]), indent=2)
else:
return libjson.dumps(dict(method=json["method"], id=json["id"], response="bad", reason="Missing 'searchString'"), indent=2)
elif json["method"] == "SearchApp":
if "searchString" in json:
return libjson.dumps(SearchApp(json["searchString"]), indent=2)
else:
return libjson.dumps(dict(method=json["method"], id=json["id"], response="bad", reason="Missing 'searchString'"), indent=2)
elif json["method"] == "GetAppPermissionsByCategory":
if "category" in json and "subcategory" in json:
if "numResults" in json:
return libjson.dumps(GetAppPermissionsByCategory(json["category"], json["subcategory"], json["numResults"]), indent=2)
else:
return libjson.dumps(GetAppPermissionsByCategory(json["category"], json["subcategory"]), indent=2)
else:
return libjson.dumps(dict(method=json["method"], id=json["id"], response="bad", reason="Missing 'category' | 'subcategory'"), indent=2)
else:
return libjson.dumps(dict(method="NoValidMethod", id=json["id"], response="bad", reason="Method name not recognized."), indent=2)