Skip to content

Instantly share code, notes, and snippets.

@felipeandradebezerra
Created February 11, 2017 16:02
Show Gist options
  • Save felipeandradebezerra/f5f4133d49961e0762d39041324104b0 to your computer and use it in GitHub Desktop.
Save felipeandradebezerra/f5f4133d49961e0762d39041324104b0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Felipe Andrade
# @Date: 11-02-2017 11:00:00
# Get reviews from the App Store
# info@colubris.com.br
import io
import json
import urllib2
import httplib
import urllib
SERVER_URL = 'api.YOUR_SERVER.com'
APP_ID = 'YOUR_MASTER_APP_ID'
MASTER_APP_KEY = 'YOUR_APP_MASTER_KEY'
ENDPOINT = '/1/classes/Reviews'
def create(post_fields, post_headers):
connection = httplib.HTTPSConnection(SERVER_URL, 443)
connection.connect()
connection.request('POST', ENDPOINT, post_fields, post_headers)
results = json.loads(connection.getresponse().read())
print results
def checkIfExists(appId, reviewId, post_headers):
params = urllib.urlencode({"where":json.dumps({
"reviewId": reviewId,
"applicationId": appId
})})
connection = httplib.HTTPSConnection(SERVER_URL)
connection.timeout = 3
connection.connect()
connection.request('GET', ENDPOINT + '?%s' % params, '', post_headers)
results = json.loads(connection.getresponse().read())
if len(results.get('results', '')) == 0:
return False
else:
return True
# loads the client config file
with open('../parse-clients/parse-clients-config.json') as data_file:
data = json.load(data_file)
for app in data['apps']:
appStoreId = app.get('appStoreId','')
appId = app.get('appId', '')
serverURL = app.get('serverURL', '')
masterKey = app.get('masterKey', '')
restAPIKey = app.get('restAPIKey', '')
if len(appStoreId) > 0:
customer_reviews_url = 'https://itunes.apple.com/br/rss/customerreviews/id=' + appStoreId + '/sortby=mostRecent/json'
response = urllib2.urlopen(customer_reviews_url)
data = json.load(response)
entries = data['feed'].get('entry', '')
if len(entries) > 0:
app_data = entries.pop(0)
for entry in entries:
id = entry['id']['label']
uri = entry['author']['uri']['label']
name = entry['author']['name']['label']
rating = entry['im:rating']['label']
version = entry['im:version']['label']
title = entry['title']['label']
content = entry['content']['label']
post_fields = json.dumps({
'reviewId': id,
'reviewLink': uri,
'reviewAuthor': name,
'reviewRating': int(rating),
'reviewAppVersion': version,
'reviewTitle': title,
'reviewContent': content,
'applicationId': appId,
'device': 'apple'
})
post_headers = {
'X-Parse-Application-Id': APP_ID,
'X-Parse-Master-Key': MASTER_APP_KEY,
'Content-Type': 'application/json'
}
if checkIfExists(appId, id, post_headers) == True:
create(post_fields, post_headers)
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment