forked from ekampf/googleplay-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reviews.py
executable file
·75 lines (62 loc) · 1.75 KB
/
reviews.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
#!/usr/bin/python
# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None
import sys
import datetime
from pprint import pprint
from config import *
from googleplay import GooglePlayAPI
from helpers import sizeof_fmt
def print_header_line():
l = [ "authorName",
"url",
"documentVersion",
"timestampMsec",
"starRating",
"title",
"comment",
"commentId",
"deviceName",
"replyText",
"replyTimestampMsec" ]
print SEPARATOR.join(l)
def print_result_line(c):
#c.offer[0].micros/1000000.0
#c.offer[0].currencyCode
l = [
c.author.name,
c.author.urls.url,
c.documentVersion,
datetime.datetime.utcfromtimestamp(c.timestampMsec/1000.0),
c.starRating,
c.title,
c.comment.replace("\n", ' '),
c.commentId,
c.deviceName,
c.replyText.replace("\n", ' '),
c.replyTimestampMsec]
print SEPARATOR.join(unicode(i).encode('utf8') for i in l)
if (len(sys.argv) < 2):
print "Usage: %s request [package] [offset]" % sys.argv[0]
print "Returns 20 reviews for a given app package."
sys.exit(0)
request = sys.argv[1]
nb_res = 20
offset = 0
if (len(sys.argv) >= 3):
offset = int(sys.argv[2])
api = GooglePlayAPI(ANDROID_ID)
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
try:
reviews = api.reviews(request, False, 0, nb_res, offset)
except:
print "Error: something went wrong. Maybe the nb_res you specified was too big?"
sys.exit(1)
resp = reviews.getResponse
print_header_line()
try:
for c in resp.review:
if c != None:
print_result_line(c)
except Exception,e:
print e