|
@@ -575,6 +575,78 @@ def parse_yipbee_html(msg):
|
|
|
|
|
|
return [order]
|
|
|
|
|
|
+def parse_lieferservice(msg):
|
|
|
+
|
|
|
+ text = msg.get_payload()[0].get_payload(decode = True).decode('utf-8').replace('\r\n', '\n')
|
|
|
+ assert type(text) is unicode
|
|
|
+
|
|
|
+ if not 'Lieferservice.at' in text:
|
|
|
+ raise Exception('no lieferservice.at confirmation')
|
|
|
+
|
|
|
+ order_match = re.search(
|
|
|
+ ur'Your order \(.+\) at (?P<restaurant>.*)\s+'
|
|
|
+ + ur'Your order reference is: (?P<order_id>.*)\s+'
|
|
|
+ + ur'[\W\w]+'
|
|
|
+ + ur'Your order\s+'
|
|
|
+ + ur'(?P<orders_text>[\W\w]+)'
|
|
|
+ + ur'Delivery costs:\s+(?P<delivery_costs>.*)\s+',
|
|
|
+ text,
|
|
|
+ re.UNICODE,
|
|
|
+ )
|
|
|
+
|
|
|
+ order_match_groups = order_match.groupdict()
|
|
|
+
|
|
|
+ import time
|
|
|
+ import email.utils
|
|
|
+ order_date = datetime.datetime.fromtimestamp(
|
|
|
+ time.mktime(email.utils.parsedate(msg['Date']))
|
|
|
+ )
|
|
|
+
|
|
|
+ order = Order(
|
|
|
+ u'lieferservice.at',
|
|
|
+ order_match_groups['order_id'].strip(),
|
|
|
+ order_date
|
|
|
+ )
|
|
|
+
|
|
|
+ for article_match in re.finditer(
|
|
|
+ ur'(?P<quantity>\d+)x\s'
|
|
|
+ + ur'(?P<name>.*)\s'
|
|
|
+ + ur'(?P<currency>.) (?P<price>-?\d+,\d+)\s',
|
|
|
+ order_match_groups['orders_text'],
|
|
|
+ re.UNICODE,
|
|
|
+ ):
|
|
|
+ article_match_groups = article_match.groupdict()
|
|
|
+ quantity = int(article_match_groups['quantity'])
|
|
|
+ assert quantity == 1
|
|
|
+ name = re.sub(ur' +', ' ', article_match_groups['name'])
|
|
|
+ price = Sum(
|
|
|
+ float(article_match_groups['price'].replace(',', '.')),
|
|
|
+ article_match_groups['currency'],
|
|
|
+ )
|
|
|
+ if price.value < 0:
|
|
|
+ price.value *= -1
|
|
|
+ order.discounts.append(Discount(
|
|
|
+ name = name,
|
|
|
+ amount = price,
|
|
|
+ ))
|
|
|
+ else:
|
|
|
+ order.items.append(Article(
|
|
|
+ name = name,
|
|
|
+ quantity = 1,
|
|
|
+ price_brutto = price,
|
|
|
+ reseller = order_match_groups['restaurant'],
|
|
|
+ shipper = order_match_groups['restaurant'],
|
|
|
+ ))
|
|
|
+
|
|
|
+ delivery_costs = order_match_groups['delivery_costs'].strip()
|
|
|
+ assert delivery_costs == 'FREE'
|
|
|
+ order.items.append(Item(
|
|
|
+ name = u'Delivery',
|
|
|
+ price_brutto = Sum(float('0'.replace(',', '.')), u'EUR'),
|
|
|
+ ))
|
|
|
+
|
|
|
+ return [order]
|
|
|
+
|
|
|
def parse(msg):
|
|
|
|
|
|
tracebacks = {}
|
|
@@ -589,6 +661,11 @@ def parse(msg):
|
|
|
except:
|
|
|
tracebacks['oebb'] = traceback.format_exc()
|
|
|
|
|
|
+ try:
|
|
|
+ return parse_lieferservice(msg)
|
|
|
+ except:
|
|
|
+ tracebacks['lieferservice'] = traceback.format_exc()
|
|
|
+
|
|
|
try:
|
|
|
return parse_mytaxi(msg)
|
|
|
except:
|