I require to find out the phone bill due date from SMS using Python 3.4 I have used dateutil.parser and datefinder but with no success as per my use-case.
Example: sms_text = "Your phone bill for Jun'17 of Rs.72.23 due on 15-07-2017 has been sent to your regd email ID abc@xyz.com. Pls check Inbox"
Code 1:
import datefinder
due_dates = datefinder.find_dates(sms_text)
for match in due_dates:
print(match)
Result: 2017-07-17 00:00:00
Code 2:
import dateutil.parser as dparser
due_date = dparser.parse(sms_text,fuzzy=True)
print(due_date)
Result: ValueError probably because of multiple dates in the text
How can I pick the due date from such texts? The date format is not fixed but there would be 2 dates in the text: one is the month for which bill is generated and other the is the due date, in the same order. Even if I get a regular expression to parse the text, it would be great.
More sample texts:
- Hello! Your phone billed outstanding is 293.72 due date is 03rd Jul.
- Bill dated 06-JUN-17 for Rs 219 is due today for your phone No. 1234567890
- Bill dated 06-JUN-17 for Rs 219 is due on Jul 5 for your phone No. 1234567890
- Bill dated 27-Jun-17 for your operator fixedline/broadband ID 1234567890 has been sent at abc@xyz.com from xyz@abc.com. Due amount: Rs 3,764.53, due date: 16-Jul-17.
- Details of bill dated 21-JUN-2017 for phone no. 1234567890: Total Due: Rs 374.12, Due Date: 09-JUL-2017, Bill Delivery Date: 25-Jun-2017,
- Greetings! Bill for your mobile 1234567890, dtd 18-Jun-17, payment due date 06-Jul-17 has been sent on abc@xyz.com
- Dear customer, your phone bill of Rs.191.24 was due on 25-Jun-2017
- Hi! Your phone bill for Rs. 560.41 is due on 03-07-2017.