I have a python script parse an incoming payload at set a variable named "confidence" and "id" then it will evaluate if the id is equal to sam@sam and that confidence is greater than or equal to 70. Now the id is equal sam@sam but confidence is not, it will still trigger! whats wrong with my code!!?
p = eg.event.payload[2]
p = p.split(',')
id = p[0].strip()
confidence = p[1].strip()
print confidence
url = p[2].strip()
if confidence >= 70 and id == "sam@sam":
eg.TriggerEvent("FaceRec", "Unlock Door" )
else:
eg.plugins.GoogleVoice.SendSMS(u'407#####', url)
The problem is that "confidence" is a string and you are comparing it to a number. The result of comparing string to a number is consistent, but not necessarily the one you want.
Fix:
confidence = int(p[1].strip())
Ok, let's take a closer look at your code. Now, p is a string. So when you split it, the results(id and confidence) are strings. That's your problem. Since confidence is still a string when you compare the values, you are comparing a string and an int. Do this:
confidence = int(p[1].strip())
This converts the string to an int first, so, confidence will be an int. The comparison will then work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With