I tried to use pyp.Optional instead of:
pyp.Suppress(pyp.Word("-")
But I can not get this to work.
Another question I have can I make things case insensitive in some way, e.g. just look for "confirmed address" or "unconfirmed" + anyword or something similar.
Appreciate a few tips on how I could go about this.
Thanks
Werner
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the response. I should actually have gotten back to the list as I found a solution, similar approach to your suggestion, i.e. using OneOf and caseless=True.
Sorry to hear about your health problems etc, hope you got that back "under control".
PayPal is really having fun in constantly changing the format of the email they send on a purchase.
I have a problem with the latest change.
The address portion can be:
VERSION1 begin:
Buyer:
Roman Schiller
roman.schiller=40edvconsult.com
436764214725
Unconfirmed shipping address
Roman Schiller
Wallensteinstra=DFe 56/21
A-1200 Wien
Austria
Instructions to merchant:
VERSION1 end:
Or
VERSION2 begin:
-----------------------------------
JAN ONDERDIJK's UNCONFIRMED Address
-----------------------------------
JAN ONDERDIJK
VOSHOLLEI 23
BRASSCHAAT 2930
Belgium
Have you lifted your withdrawal and receiving limits?
VERSION2 end:
There are actually a few more variations which I try to handle with this code (only showing snippets):
addLine = pyp.Combine((pyp.OneOrMore(alphanums) + pyp.restOfLine))
emptyLine = (pyp.Suppress("Thank you for using PayPal") |\ (pyp.Suppress("Have you lifted your withdrawal") + pyp.restOfLine) |\ (pyp.Suppress("Sincerely,") + pyp.restOfLine) |\ (pyp.Suppress(pyp.OneOrMore('-')) + pyp.Suppress("Have you lifted your withdrawal") + pyp.restOfLine) |\ (pyp.Suppress("Instructions to") + pyp.restOfLine))
....
# address
str_address = (((pyp.Suppress("UNCONFIRMED Address") |\ pyp.Suppress("CONFIRMED Address") |\ pyp.Suppress("unconfirmed address")) |\ pyp.Suppress("Unconfirmed shipping address") + pyp.Suppress(pyp.Word("-"))) +\ ((addLine + addLine + addLine + addLine + emptyLine.suppress()) |\ (addLine + addLine + addLine + addLine + addLine + emptyLine.suppress()) |\ (addLine + addLine + addLine + addLine + addLine + addLine + emptyLine.suppress()) ))
I tried to use pyp.Optional instead of:
pyp.Suppress(pyp.Word("-")
But I can not get this to work.
Another question I have can I make things case insensitive in some way, e.g. just look for "confirmed address" or "unconfirmed" + anyword or something similar.
Appreciate a few tips on how I could go about this.
Thanks
Werner
CaselessLiteral("confirmed address") should handle case-insensitive matching.
All I can suggest is you try adding setName and setDebug() calls on some of your key expressions, and see where expected matches fail.
(Sorry to be so slow in responding - I've had a difficult couple of months both health and job-wise - thanks for your patience.)
-- Paul
Paul,
Thanks for the response. I should actually have gotten back to the list as I found a solution, similar approach to your suggestion, i.e. using OneOf and caseless=True.
Sorry to hear about your health problems etc, hope you got that back "under control".
All the best
Werner
addressStart = pyp.oneOf("unconfirmed shipping address;"
"confirmed shipping address;"
"adresse de livraison :;"
"confirmed address;"
"ship-to address:;"
"ship-to address: - unconfirmed".split(';'), caseless=True) +\ pyp.Optional(pyp.Word("-")).suppress()