|
@@ -0,0 +1,57 @@
|
|
|
+
|
|
|
+
|
|
|
+import datetime
|
|
|
+import dingguo
|
|
|
+import string
|
|
|
+import email
|
|
|
+import ioex
|
|
|
+import re
|
|
|
+import BeautifulSoup
|
|
|
+
|
|
|
+def parse_order_confirmation_mail(mail):
|
|
|
+
|
|
|
+ assert isinstance(mail, email.message.Message)
|
|
|
+
|
|
|
+ html_mail = mail.get_payload()[0].get_payload()[1].get_payload(decode = True)
|
|
|
+
|
|
|
+ doc = BeautifulSoup.BeautifulSoup(html_mail)
|
|
|
+
|
|
|
+ order_attr = re.search(
|
|
|
+ ur'Bestelldatum:(?P<date>\d+)'
|
|
|
+ + ur'Benutzername:(?P<user>.*)'
|
|
|
+ + ur'Name',
|
|
|
+ doc.find(text = 'Bestelldatum:').findParent('table').text,
|
|
|
+ re.UNICODE,
|
|
|
+ ).groupdict()
|
|
|
+ user = ''.join([c if (c in string.printable) else '' for c in order_attr['user']])
|
|
|
+ order = dingguo.Order(
|
|
|
+ customer_id = user,
|
|
|
+ order_date = datetime.datetime.strptime(order_attr['date'], '%d%m%y'),
|
|
|
+ order_id = u'%s-%s' % (user, order_attr['date']),
|
|
|
+ platform = u'hm',
|
|
|
+ )
|
|
|
+
|
|
|
+ for article_tag in [t.findParents('tr')[2] for t in doc.findAll(text = 'Art.-Nr.:')]:
|
|
|
+ article_subtags = article_tag.findAll(recursive = False)
|
|
|
+ article = re.search(
|
|
|
+ ur'Art.-Nr.:(?P<id>[\d-]+)'
|
|
|
+ + ur'Beschreibung:(?P<label>.*)'
|
|
|
+ + ur'Größe:(?P<size>.*)'
|
|
|
+ + ur'Farbe:(?P<color>[^\d]+)',
|
|
|
+ article_subtags[1].text,
|
|
|
+ re.UNICODE,
|
|
|
+ ).groupdict()
|
|
|
+ order.items.append(dingguo.Article(
|
|
|
+ color = article['color'],
|
|
|
+ name = article['label'],
|
|
|
+ price_brutto = dingguo.Sum(
|
|
|
+ float(article_subtags[3].text.replace(',', '.')),
|
|
|
+ u'EUR',
|
|
|
+ ),
|
|
|
+ product_id = article['id'],
|
|
|
+ quantity = int(article_subtags[2].text),
|
|
|
+ reseller = u'H&M',
|
|
|
+ size = article['size'],
|
|
|
+ ))
|
|
|
+
|
|
|
+ return [order]
|