I have a simple web service application that I'm using to test sending pushes through Parse.com from Python.
My app uses Flask module and ParsePy module. The code listed below works for the Push.alert(notification, channels=["pushDebug"])
- I see a notification on the device subscribed to that channel.
Now I'm trying to send a push to a specific device ID, but am not seeing the notification go through.
What is the correct syntax to define a "Where" query for a specific user ID (a custom field defined in Parse)? Here's the line of code that needs this query: Push.alert(notification, where={"kDeviceID": str(deviceID)})
Examples I found
Push.alert({"alert": "The Mets scored! The game is now tied 1-1.",
"badge": "Increment", "title": "Mets Score"}, channels=["Mets"],
where={"scores": True})
OR (taken from parse official documentation)
"where": {
"user_id": "user_123"
}
My webservice:
from flask import Flask
from flask import Response, jsonify, request, redirect, url_for
from parse_rest.connection import register
from parse_rest.installation import Push
import socket
app = Flask(__name__)
didRegisterWithParse = 0
def checkRegister():
if didRegisterWithParse == 0:
register(
"APPLICATION_ID",
"REST_API_KEY",
master_key="MASTER_KEY"
)
global didRegisterWithParse
didRegisterWithParse = 1
return
@app.route('/testparsepush/')
def testparsepush():
deviceID = request.args.get('device_id')
hostString = "http://%s:5000/getcommand/" % socket.gethostbyname(socket.gethostname())
notification = {"alert": "Parse Test","title": "Push from Python", "host": hostString}
checkRegister()
# send push notification through parse
resp = None
if deviceID:
Push.alert(notification, where={"kDeviceID": str(deviceID)})
#prepare response
resp = jsonify(message = 'sent alert to deviceID: ' + str(deviceID))
else:
Push.alert(notification, channels=["pushDebug"])
resp = jsonify(message = 'sent alert to channel pushDebug')
resp.status_code = 200
return resp
if __name__ == '__main__':
print(socket.gethostbyname(socket.gethostname()))
app.run(host='0.0.0.0')