|
@@ -31,13 +31,14 @@ def parse_order_confirmation_mail(mail):
|
|
|
raise Exception()
|
|
|
|
|
|
order_match = re.search(
|
|
|
- r'(?P<name>Single-Ticket)\s+'
|
|
|
+ r'(?P<name>.*Ticket.*)\s+'
|
|
|
+ r'Valid from: (?P<valid_from>\d{1,2} \w+ \d{4} \d{1,2}:\d{2})\s+'
|
|
|
- + r'Type: (?P<type>Mobile ticket)\s+'
|
|
|
+ + r'(Valid until: (?P<valid_until>\d{1,2} \w+ \d{4} \d{1,2}:\d{2})\s+)?'
|
|
|
+ + r'Type: (?P<type>.* ticket)\s+'
|
|
|
+ r'For\:\s+'
|
|
|
+ r'(?P<passenger_first_name>Fabian Peter)\s+'
|
|
|
+ r'(?P<passenger_last_name>Hammerle)\s+'
|
|
|
- + ur'Price: (?P<currency>€)(?P<price>2.80)\s+'
|
|
|
+ + ur'Price: (?P<currency>€)(?P<price>\d+.\d{2})\s+'
|
|
|
+ r'Quantity: (?P<quantity>1)\s+'
|
|
|
,
|
|
|
msg_text,
|
|
@@ -61,8 +62,14 @@ def parse_order_confirmation_mail(mail):
|
|
|
|
|
|
assert int(order_match_groups['quantity']) == 1
|
|
|
|
|
|
+ ticket_url_match = re.search(
|
|
|
+ ur'following link:\s+(http[^\s]+)',
|
|
|
+ msg_text,
|
|
|
+ re.MULTILINE | re.UNICODE,
|
|
|
+ )
|
|
|
+
|
|
|
with ioex.setlocale('en_US.UTF-8'):
|
|
|
- import pytz
|
|
|
+ timezone = UtcOffsetTimezone(email.utils.parsedate_tz(mail['date'])[9])
|
|
|
order.items.append(dingguo.Transportation(
|
|
|
name = order_match_groups['name'],
|
|
|
price_brutto = dingguo.Sum(
|
|
@@ -74,7 +81,10 @@ def parse_order_confirmation_mail(mail):
|
|
|
last_name = order_match_groups['passenger_last_name'],
|
|
|
),
|
|
|
valid_from = datetime.datetime.strptime(order_match_groups['valid_from'], '%d %B %Y %H:%M')
|
|
|
- .replace(tzinfo = UtcOffsetTimezone(email.utils.parsedate_tz(mail['date'])[9]))
|
|
|
+ .replace(tzinfo = timezone),
|
|
|
+ valid_until = datetime.datetime.strptime(order_match_groups['valid_until'], '%d %B %Y %H:%M')
|
|
|
+ .replace(tzinfo = timezone) if order_match_groups['valid_until'] else None,
|
|
|
+ ticket_url = ticket_url_match.group(1) if ticket_url_match else None,
|
|
|
))
|
|
|
|
|
|
return [order]
|