|
@@ -1,6 +1,8 @@
|
|
|
|
|
|
|
|
|
import datetime
|
|
|
+import dateutil
|
|
|
+import dateutil.tz
|
|
|
import dingguo
|
|
|
import email
|
|
|
import ioex
|
|
@@ -22,11 +24,13 @@ def parse_order_confirmation_mail(mail):
|
|
|
order_id = re.search(r'Bestellnummer #(.+)', order_text).group(1)
|
|
|
|
|
|
order_date_formatted = re.search(ur'Aufgegeben am (.+)', order_text, re.UNICODE).group(1)
|
|
|
+ mail_date = dateutil.parser.parse(mail['date'])
|
|
|
with ioex.setlocale('de_DE.UTF-8'):
|
|
|
order_date = datetime.datetime.strptime(
|
|
|
order_date_formatted.encode('utf-8'),
|
|
|
'%d. %B %Y',
|
|
|
)
|
|
|
+ assert order_date.date() == mail_date.date()
|
|
|
|
|
|
order = dingguo.Order(
|
|
|
u'amazon.de',
|
|
@@ -67,6 +71,32 @@ def parse_order_confirmation_mail(mail):
|
|
|
shipper = article['shipper'],
|
|
|
))
|
|
|
|
|
|
+ assert re.search(
|
|
|
+ ur'Verpackung und Versand: \w+ (\d+,\d+)',
|
|
|
+ order_text,
|
|
|
+ ).group(1) == '0,00'
|
|
|
+ shipping_match = re.finditer(
|
|
|
+ ur'Zustellung:\s+(?P<t>[\W\w]+?)\s+'
|
|
|
+ + ur'Versandart',
|
|
|
+ order_text,
|
|
|
+ re.UNICODE,
|
|
|
+ )
|
|
|
+ for shipping_attr in [m.groupdict() for m in shipping_match]:
|
|
|
+ with ioex.setlocale('de_AT.UTF-8'):
|
|
|
+ s = datetime.datetime.strptime(
|
|
|
+ shipping_attr['t'].encode('utf8'),
|
|
|
+ '%A, %d. %B',
|
|
|
+ ).replace(
|
|
|
+ year = order.order_date.year,
|
|
|
+ tzinfo = dateutil.tz.gettz('Europe/Berlin'),
|
|
|
+ )
|
|
|
+ assert s.date() > order.order_date
|
|
|
+ e = s + datetime.timedelta(days = 1)
|
|
|
+ order.items.append(dingguo.Shipping(
|
|
|
+ price_brutto = dingguo.Sum(0.0, u'EUR'),
|
|
|
+ estimated_arrival_time = ioex.datetimeex.Period(start = s, end = e),
|
|
|
+ ))
|
|
|
+
|
|
|
orders.append(order)
|
|
|
|
|
|
return orders
|