Browse Source

support for namecheap; indiegogo: added support for confirms with reward in english

Fabian Peter Hammerle 7 years ago
parent
commit
facb1932cf
2 changed files with 9 additions and 7 deletions
  1. 6 4
      dingguo/parser/indiegogo.py
  2. 3 3
      tests/parser/test_indiegogo.py

+ 6 - 4
dingguo/parser/indiegogo.py

@@ -51,11 +51,13 @@ def parse_order_confirmation_mail(mail):
         reward = reward_label_tag.findNext().text if reward_label_tag else None,
         ))
 
-    shipping_costs_label_tag = doc.find(text = re.compile(u'Versand:'))
+    shipping_costs_label_tag = doc.find(text = re.compile(u'(Versand|Shipping):'))
     if shipping_costs_label_tag:
-        with ioex.setlocale('de_AT.utf8'):
+        with ioex.setlocale('de_AT.utf8' if 'Versand' in shipping_costs_label_tag else 'en_US.utf8'):
             estimated_arrival_start = datetime.datetime.strptime(
-                    doc.find(text = re.compile('Voraussichtliche Lieferung:')).findNext().text,
+                    doc.find(
+                        text = re.compile('(Voraussichtliche Lieferung|Estimated Delivery):')
+                        ).findNext().text,
                     '%B %Y'
                     ).replace(tzinfo = email_date.tzinfo)
         order.items.append(dingguo.Shipping(
@@ -66,7 +68,7 @@ def parse_order_confirmation_mail(mail):
                 start = estimated_arrival_start,
                 end = (estimated_arrival_start + datetime.timedelta(days = 32)).replace(day = 1),
                 ),
-            destination_point = doc.find(text = re.compile('Lieferadresse:'))
+            destination_point = doc.find(text = re.compile('(Lieferadresse|Shipping Address):'))
                 .findNext().text.replace('\r\n', '\n'),
             ))
 

+ 3 - 3
tests/test_parser_indiegogo.py → tests/parser/test_indiegogo.py

@@ -5,11 +5,11 @@ import pytest
 import dingguo.parser.indiegogo
 import email
 import glob
+import ioex
 import os
-import test_yaml
 import yaml
 
-project_root_path = os.path.realpath(os.path.join(__file__, '..', '..'))
+project_root_path = os.path.realpath(os.path.join(__file__, '..', '..', '..'))
 test_data_path = os.path.join(project_root_path, 'tests', 'data', 'indiegogo')
 
 @pytest.mark.parametrize('mail_path', glob.glob(os.path.join(test_data_path, '*.eml')))
@@ -21,4 +21,4 @@ def test_parse_confirmation_mail(mail_path):
     with open(mail_path.replace('.eml', '.yml')) as yaml_file:
         expected_orders = yaml.load(yaml_file.read())
     assert expected_orders == parsed_orders, \
-            test_yaml.yaml_diff(expected_orders, parsed_orders)
+            u'\n%s' % ioex.yaml_diff(expected_orders, parsed_orders, colors = True)