| 
					
				 | 
			
			
				@@ -179,48 +179,57 @@ def parse_amazon(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     msg_text = msg.get_payload()[0].get_payload(decode = True).decode('utf-8') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    order_id = re.search(r'Bestellnummer #(.+)', msg_text).group(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if not u'Amazon.de Bestellbestätigung' in msg_text: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        raise Exception('no amazon order confirmation') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    order_date_formatted = re.search(ur'Aufgegeben am (.+)', msg_text, re.UNICODE).group(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    order_date = datetime.datetime.strptime(order_date_formatted.encode('utf-8'), '%d. %B %Y') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    orders = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    order = Order( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        u'amazon.de', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        order_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        order_date 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for order_text in re.split(ur'={32,}', msg_text)[1:-1]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        order_id = re.search(r'Bestellnummer #(.+)', order_text).group(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    articles_text = msg_text.split('Bestellte(r) Artikel:')[1].split('_' * 10)[0].strip() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    for article_text in re.split(ur'\n\t*\n', articles_text): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        article_match = re.match( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ur' *((?P<quantity>\d+) x )?(?P<name>.*)\n' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                + ur'( *von (?P<authors>.*)\n)?' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                + ur' *(?P<price_brutto_currency>[A-Z]+) (?P<price_brutto>\d+,\d+)\n' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                + ur'( *Zustand: (?P<state>.*)\n)?' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                + ur' *Verkauft von: (?P<reseller>.*)' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                + ur'(\n *Versand durch (?P<shipper>.*))?', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            article_text, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            re.MULTILINE | re.UNICODE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        order_date_formatted = re.search(ur'Aufgegeben am (.+)', order_text, re.UNICODE).group(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        order_date = datetime.datetime.strptime(order_date_formatted.encode('utf-8'), '%d. %B %Y') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        order = Order( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            u'amazon.de', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            order_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            order_date 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if article_match is None: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            sys.stderr.write(repr(article_text) + '\n') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            raise Exception('could not match article') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        article = article_match.groupdict() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        order.items.append(Article( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            name = article['name'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            price_brutto = Sum( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                float(article['price_brutto'].replace(',', '.')), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                article['price_brutto_currency'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            quantity = int(article['quantity']) if article['quantity'] else 1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            authors = article['authors'].split(',') if article['authors'] else [], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            state = article['state'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            reseller = article['reseller'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            shipper = article['shipper'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            )) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        articles_text = order_text.split('Bestellte(r) Artikel:')[1].split('_' * 10)[0].strip() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for article_text in re.split(ur'\n\t*\n', articles_text): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            article_match = re.match( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ur' *((?P<quantity>\d+) x )?(?P<name>.*)\n' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    + ur'( *von (?P<authors>.*)\n)?' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    + ur' *(?P<price_brutto_currency>[A-Z]+) (?P<price_brutto>\d+,\d+)\n' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    + ur'( *Zustand: (?P<state>.*)\n)?' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    + ur' *Verkauft von: (?P<reseller>.*)' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    + ur'(\n *Versand durch (?P<shipper>.*))?', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                article_text, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                re.MULTILINE | re.UNICODE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if article_match is None: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sys.stderr.write(repr(article_text) + '\n') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                raise Exception('could not match article') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            article = article_match.groupdict() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            order.items.append(Article( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                name = article['name'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                price_brutto = Sum( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    float(article['price_brutto'].replace(',', '.')), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    article['price_brutto_currency'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                quantity = int(article['quantity']) if article['quantity'] else 1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                authors = article['authors'].split(',') if article['authors'] else [], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                state = article['state'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                reseller = article['reseller'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                shipper = article['shipper'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                )) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        orders.append(order) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return orders 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def parse_oebb(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -273,7 +282,7 @@ def parse_oebb(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         destination_point = item['destination_point'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         )) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return [order] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def parse_mytaxi(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -342,7 +351,7 @@ def parse_mytaxi(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         driver = ride_match_groups['driver'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         arrival_time = arrival_time, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         )) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return [order] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def parse_yipbee(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -408,7 +417,7 @@ def parse_yipbee(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         price_brutto = Sum(float(delivery_price_value.replace(',', '.')), delivery_price_currency), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         )) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return [order] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def parse_yipbee_html(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -459,7 +468,7 @@ def parse_yipbee_html(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         price_brutto = Sum(float(shipping_price), shipping_currency), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         )) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return [order] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def parse(msg): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -494,22 +503,23 @@ def compute(register_path): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     msg = email.message_from_string(sys.stdin.read()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    order = parse(msg) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    orders = parse(msg) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if register_path: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         with open(register_path, 'r') as register: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orders = yaml.load(register.read().decode('utf-8')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if not orders: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orders = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if order.platform not in orders: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            orders[order.platform] = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if order.order_id in orders[order.platform]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            raise Exception('already registered') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        orders[order.platform][order.order_id] = order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            registered_orders = yaml.load(register.read().decode('utf-8')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if not registered_orders: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            registered_orders = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for order in orders: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if order.platform not in registered_orders: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                registered_orders[order.platform] = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if order.order_id in registered_orders[order.platform]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                raise Exception('already registered') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            registered_orders[order.platform][order.order_id] = order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         with open(register_path, 'w') as register: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            register.write(yaml.safe_dump(orders, default_flow_style = False)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            register.write(yaml.safe_dump(registered_orders, default_flow_style = False)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        print(yaml.safe_dump(order, default_flow_style = False)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print(yaml.safe_dump(orders, default_flow_style = False)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def _init_argparser(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |