Created
August 19, 2013 17:47
-
-
Save 8vius/6271976 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from order import Order, BundleOrders | |
def parser(html=None, plain=None, attachments=None, debug=False): | |
if html == None: | |
html = '' | |
if plain == None: | |
plain = '' | |
message_contents = '{0}{1}'.format(html, plain) | |
patterns = [ | |
'Booking', | |
'Fare Code', | |
] | |
positive_matches = [] | |
for pattern in patterns: | |
if re.search(pattern, message_contents): | |
positive_matches.append(pattern) | |
if len(positive_matches) == 0: | |
error_message = 'The message doesn\'t contain any of the patterns.' | |
else: | |
error_message = 'The message contained pattern(s): ' | |
for positive_match in positive_matches[:-1]: | |
error_message += '"{0}", '.format(positive_match) | |
if len(positive_matches) > 1: | |
error_message += 'and ' | |
error_message += '"{0}".'.format(positive_matches[-1]) | |
raise StandardError(error_message) | |
order = Order(merchant='Acme') | |
orderbundle = BundleOrders(order) | |
return orderbundle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment