Explorar o código

oebb: support german

Fabian Peter Hammerle %!s(int64=8) %!d(string=hai) anos
pai
achega
13df928d88
Modificáronse 1 ficheiros con 18 adicións e 11 borrados
  1. 18 11
      dingguo/parser/oebb.py

+ 18 - 11
dingguo/parser/oebb.py

@@ -22,19 +22,26 @@ def parse_order_confirmation_mail(mail):
     #     )
     #     )
 
 
     order_match = re.search(
     order_match = re.search(
-        ur'Booking code:\s+(?P<order_id>[\d ]+)\s+'
-            + ur'Customer number:\s+(?P<customer_id>PV\d+)\s+'
-            + ur'Booking date:\s+(?P<order_date>.* \d{4})\s',
+        ur'(?P<order_id_label>Booking code|Buchungscode):\s+(?P<order_id>[\d ]+)\s+'
+            + ur'(Customer number|Kundennummer):\s+(?P<customer_id>PV\d+)\s+'
+            + ur'(Booking date|Buchungsdatum):\s+(?P<order_date>.* \d{4})\s',
         msg_text,
         msg_text,
         re.MULTILINE | re.UNICODE
         re.MULTILINE | re.UNICODE
         )
         )
     order_match_groups = order_match.groupdict()
     order_match_groups = order_match.groupdict()
 
 
-    with ioex.setlocale('en_US.UTF-8'):
-        order_date = datetime.datetime.strptime(
-            order_match_groups['order_date'],
-            '%b %d, %Y',
-            )
+    if order_match_groups['order_id_label'] == 'Buchungscode':
+        with ioex.setlocale('de_AT.UTF-8'):
+            order_date = datetime.datetime.strptime(
+                order_match_groups['order_date'],
+                '%d. %b %Y',
+                )
+    else:
+        with ioex.setlocale('en_US.UTF-8'):
+            order_date = datetime.datetime.strptime(
+                order_match_groups['order_date'],
+                '%b %d, %Y',
+                )
 
 
     order = dingguo.Order(
     order = dingguo.Order(
         u'oebb',
         u'oebb',
@@ -44,9 +51,9 @@ def parse_order_confirmation_mail(mail):
         )
         )
 
 
     item_match = re.search(
     item_match = re.search(
-        ur'(?P<price_brutto_currency>.)(?P<price_brutto>\d+\.\d+)'
+        ur'(?P<price_brutto_currency>.) ?(?P<price_brutto>\d+(\.|,)\d+)'
             + ur'[\W\w]+'
             + ur'[\W\w]+'
-            + ur'Your Bookings?\s+'
+            + ur'(Your Bookings?|Ihre Buchung)\s+'
             + ur'(?P<departure_point>.*)\s+>\s+(?P<destination_point>.*)',
             + ur'(?P<departure_point>.*)\s+>\s+(?P<destination_point>.*)',
         msg_text,
         msg_text,
         re.MULTILINE | re.UNICODE
         re.MULTILINE | re.UNICODE
@@ -55,7 +62,7 @@ def parse_order_confirmation_mail(mail):
     order.items.append(dingguo.Transportation(
     order.items.append(dingguo.Transportation(
         name = u'Train Ticket',
         name = u'Train Ticket',
         price_brutto = dingguo.Sum(
         price_brutto = dingguo.Sum(
-            float(item['price_brutto']),
+            float(item['price_brutto'].replace(',', '.')),
             item['price_brutto_currency'],
             item['price_brutto_currency'],
             ),
             ),
         departure_point = item['departure_point'],
         departure_point = item['departure_point'],