|
@@ -0,0 +1,71 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import datetime
|
|
|
|
+import dingguo
|
|
|
|
+import email
|
|
|
|
+import re
|
|
|
|
+
|
|
|
|
+def parse_order_confirmation_mail(mail):
|
|
|
|
+
|
|
|
|
+ assert isinstance(mail, email.message.Message)
|
|
|
|
+
|
|
|
|
+ mail_text = mail.get_payload()[0].get_payload(decode = True).decode('iso-8859-1')
|
|
|
|
+
|
|
|
|
+ if not u'Danke für deine Bestellung bei IKEA' in mail_text:
|
|
|
|
+ raise Exception('no ikea order confirmation')
|
|
|
|
+
|
|
|
|
+ order = dingguo.Order(
|
|
|
|
+ order_id = re.search(ur'Bestellnummer:\s+(\d+)', mail_text).group(1),
|
|
|
|
+ order_date = datetime.datetime.strptime(
|
|
|
|
+ re.search(ur'Bestelldatum:\s+(\d\d-\d\d-\d{4})', mail_text).group(1),
|
|
|
|
+ '%d-%m-%Y',
|
|
|
|
+ ).date(),
|
|
|
|
+ platform = u'ikea',
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for article_text in re.findall(ur'Menge[\W\w]+?Gesamtpreis', mail_text):
|
|
|
|
+ article_attr = re.match(
|
|
|
|
+ ur'Menge\s+(?P<quantity>\d+)\s+'
|
|
|
|
+ + ur'Produkt\s+(?P<name>.+)\s+'
|
|
|
|
+ + ur'(?P<label>.+)\s+'
|
|
|
|
+ + ur'(Breite: (?P<width>\d+) (?P<width_unit>[^\s]+)\s+)?'
|
|
|
|
+ + ur'(Tiefe: (?P<depth>\d+) (?P<depth_unit>[^\s]+)\s+)?'
|
|
|
|
+ + ur'(Höhe: (?P<height>\d+) (?P<height_unit>[^\s]+)\s+)?'
|
|
|
|
+ + ur'(Max Belastung: (?P<maximum_load>\d+) (?P<maximum_load_unit>[^\s]+)\s+)?'
|
|
|
|
+ + ur'Artikelnummer: (?P<product_id>[\d\.]+)\s+'
|
|
|
|
+ + ur'Einzelpreis \? (?P<price>\d+,\d*)-?\s+'
|
|
|
|
+ + ur'Gesamtpreis',
|
|
|
|
+ article_text,
|
|
|
|
+ re.UNICODE,
|
|
|
|
+ ).groupdict()
|
|
|
|
+ order.items.append(dingguo.Article(
|
|
|
|
+ depth = dingguo.ScalarFigure(float(article_attr['depth']), article_attr['depth_unit']) if article_attr['depth'] else None,
|
|
|
|
+ height = dingguo.ScalarFigure(float(article_attr['height']), article_attr['height_unit']) if article_attr['height'] else None,
|
|
|
|
+ maximum_load = dingguo.ScalarFigure(float(article_attr['maximum_load']), article_attr['maximum_load_unit']) if article_attr['maximum_load'] else None,
|
|
|
|
+ name = u'%s %s' % (article_attr['name'].strip(), article_attr['label'].strip().replace(' , ', ', ')),
|
|
|
|
+ price_brutto = dingguo.Sum(float(article_attr['price'].replace(',', '.')), u'EUR'),
|
|
|
|
+ product_id = article_attr['product_id'],
|
|
|
|
+ quantity = int(article_attr['quantity']),
|
|
|
|
+ width = dingguo.ScalarFigure(float(article_attr['width']), article_attr['width_unit']) if article_attr['width'] else None,
|
|
|
|
+ ))
|
|
|
|
+
|
|
|
|
+ return [order]
|