I came across lots of people asking how to retrieve the Sender's number from a received SMS in Python even if the contact is in your contacts database.
Here is a quick fix:
Incorporate this to your code to be able to get the number.Code:# Contact Number from Contacts dB # XenoArts - John Robert Planta import contacts #import contact db db = contacts.open() #store in a variable "db" def getSenderNum(sms_sender): found = db.find(sms_sender) #find in database the contact name try: found #check if found except NameError: senderData = found[0] senderNum = senderData.find("mobile_number")[0].value else: senderNum = sms_sender return senderNum #now all you have to do is assign a variable the number of that contact name mobileNum = getSenderNum(contactName) #change contactName to whatever variable you stored your ripped contact
Good Luck.

Reply With Quote

