I'm having trouble trying too get an acknowledgement from pushover using python.
In my script I'm using a dict to send the same message to 2 people and record once the message has been acknowledged. The reason I'm doing it this way and not in a group is because if one person acknowledges then it cancels the call for rest so if one person sees it and acknowledges and another doesn't then the alert stops for the group.
So far my code will send the message for both uid but will not print once they have acknowledged
import time
import requests
import datetime
dict = {'u56pt7jQXxgmtGnX5MBgsnUz4kgqKS': 'User1', 'uoREW3cuvy3SbSnyc7Ra737nVbrBQh': 'user2'}
app = "app id"
for k in dict:
user = k
params = {
'token': app,
'user': user,
'title': 'lala',
'message': 'test',
'retry': 300,
'expire': 40,
'priority': 2 ,
'sound': 'siren',
}
msg = requests.post('https://api.pushover.net/1/messages.json', data=params)
print "POSTed message to " + k
json_data = msg.json()
print json_data['receipt']
time.sleep(5)
d = json_data['receipt']
v = requests.get("https://api.pushover.net/1/receipts/"+ d + ".json?token=" + app)
out = v.json()
while out['acknowledged'] is 0:
print "not yet" #placed for debugging
time.sleep(5)
v = requests.get("https://api.pushover.net/1/receipts/"+ d + ".json?token=" + app)
if out['acknowledged'] is 1:
ack = out['acknowledged_by']
for k in dict:
if ack in k:
acked = dict[k]
t = datetime.datetime.strftime(datetime.datetime.now(), '%H:%M')
print (acked + " acknowledged at " + t)
UPDATE
Using code provided below this now recheck the while statement but still only acknowledges the second dict entry.
Looking over the code I believe the
v = requests.get("https://api.pushover.net/1/receipts/"+ d + ".json?token=" + app)
is only checking the second dict entry not both.