Commits

Anonymous committed 9012e5c

Extracted get factor method; fixed yahoo currencies sync.

  • Participants
  • Parent commits 2e70ff3

Comments (0)

Files changed (2)

         """
         Convert from one currency to another.
         """
+        amount = self.amount * self.get_factor(currency, source)
+        return Money(amount, currency)
+
+    def get_factor(self, currency, source=None):
         currency = get_currency(currency)
         self_factor = self.currency.get_factor(source)
         other_factor = currency.get_factor(source)
-        amount = (self.amount / self_factor) * other_factor
-        return Money(amount, currency)
+        return other_factor / self_factor
 
 
 #

money/sync/yahoo.py

     def _parse(self, f):
         for row in csv.reader(f):
             code, factor, date, time = row
+            try:
+                date_time = datetime.strptime('%s %s' % 
+                                              (date, time), "%m/%d/%Y %I:%M%p")
+            except ValueError:
+                date = time = 'N/A'
             if date == 'N/A' or time == 'N/A':
                 now = datetime.now()
                 date = now.strftime("%m/%d/%Y")
                 time = now.strftime("%I:%M%p")
             yield (code[3:6], dc(factor),
-                   datetime.strptime('%s %s' % (date, time), "%m/%d/%Y %I:%M%p"))
+                   date_time)
 
     def _get_url(self, default_currency_code, currencies):
         return 'http://download.finance.yahoo.com/d/quotes.csv?f=sl1d1t1' + \