Skip to content

Instantly share code, notes, and snippets.

@8vius
Created August 19, 2013 17:47
Show Gist options
  • Save 8vius/6271976 to your computer and use it in GitHub Desktop.
Save 8vius/6271976 to your computer and use it in GitHub Desktop.
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